Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read data and add it to a chart

Read data and add it to a chart

Scheduled Pinned Locked Moved Unsolved General and Desktop
chartreal time plotplottingtimerfile read
28 Posts 5 Posters 5.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 4 Jan 2021, 09:52 last edited by
    #17

    Hi
    Please show one line from the "C:/Users/ilknu/Documents/QFileDemo/abc.txt"
    so we know how data is. else it's impossible to give any hints on how you can show that in a chart.

    D 1 Reply Last reply 4 Jan 2021, 10:39
    0
    • M mrjj
      4 Jan 2021, 09:52

      Hi
      Please show one line from the "C:/Users/ilknu/Documents/QFileDemo/abc.txt"
      so we know how data is. else it's impossible to give any hints on how you can show that in a chart.

      D Offline
      D Offline
      deleted286
      wrote on 4 Jan 2021, 10:39 last edited by
      #18

      @mrjj Here it is

      1991 01 213.5 136.9 0.64 220.5 147.6 229.4 205.5 8 17.4
      1991 02 270.2 167.5 0.62 221.5 147.6 243.0 206.3 10 18.4

      J 1 Reply Last reply 4 Jan 2021, 10:49
      0
      • D deleted286
        4 Jan 2021, 10:39

        @mrjj Here it is

        1991 01 213.5 136.9 0.64 220.5 147.6 229.4 205.5 8 17.4
        1991 02 270.2 167.5 0.62 221.5 147.6 243.0 206.3 10 18.4

        J Offline
        J Offline
        JonB
        wrote on 4 Jan 2021, 10:49 last edited by JonB 1 Apr 2021, 10:53
        #19

        @suslucoder

        QString line = read_one_line_from_file();
        QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
        for (const QString &entry : list)
        {
            double num = entry.toDouble();    // or `unsigned num = entry.toUInt()` for the first 2 numbers on each line, by the look of it
            // do whatever is necessary with each `double` number retrieved
            // such as adding pairs directly to the chart, or building a `QLineSeries`, or whatever
        }
        
        D 1 Reply Last reply 4 Jan 2021, 11:03
        1
        • J JonB
          4 Jan 2021, 10:49

          @suslucoder

          QString line = read_one_line_from_file();
          QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
          for (const QString &entry : list)
          {
              double num = entry.toDouble();    // or `unsigned num = entry.toUInt()` for the first 2 numbers on each line, by the look of it
              // do whatever is necessary with each `double` number retrieved
              // such as adding pairs directly to the chart, or building a `QLineSeries`, or whatever
          }
          
          D Offline
          D Offline
          deleted286
          wrote on 4 Jan 2021, 11:03 last edited by
          #20

          @JonB Thank you. Where should I place the code script?

          J 1 Reply Last reply 4 Jan 2021, 12:10
          0
          • D deleted286
            4 Jan 2021, 11:03

            @JonB Thank you. Where should I place the code script?

            J Online
            J Online
            jsulm
            Lifetime Qt Champion
            wrote on 4 Jan 2021, 12:10 last edited by
            #21

            @suslucoder said in Read data and add it to a chart:

            Where should I place the code script?

            Come on. Place is where you read the data from the file...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            D 1 Reply Last reply 4 Jan 2021, 12:12
            0
            • J jsulm
              4 Jan 2021, 12:10

              @suslucoder said in Read data and add it to a chart:

              Where should I place the code script?

              Come on. Place is where you read the data from the file...

              D Offline
              D Offline
              deleted286
              wrote on 4 Jan 2021, 12:12 last edited by
              #22

              @jsulm I know but i have, QString line = in.readLine();
              allLines.append(line);
              I couldnt get the idea about it. When i do it i get out of index error .And after doing all this things, how can i add my datas to a chart?

              D J 2 Replies Last reply 4 Jan 2021, 12:26
              0
              • D deleted286
                4 Jan 2021, 12:12

                @jsulm I know but i have, QString line = in.readLine();
                allLines.append(line);
                I couldnt get the idea about it. When i do it i get out of index error .And after doing all this things, how can i add my datas to a chart?

                D Offline
                D Offline
                deleted286
                wrote on 4 Jan 2021, 12:26 last edited by
                #23

                @suslucoder I did this part. After that, how can i add it to a chart? Like the way create a new chart, append series and it goes like this?

                1 Reply Last reply
                0
                • D deleted286
                  4 Jan 2021, 12:12

                  @jsulm I know but i have, QString line = in.readLine();
                  allLines.append(line);
                  I couldnt get the idea about it. When i do it i get out of index error .And after doing all this things, how can i add my datas to a chart?

                  J Online
                  J Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on 4 Jan 2021, 12:27 last edited by
                  #24

                  @suslucoder said in Read data and add it to a chart:

                  And after doing all this things, how can i add my datas to a chart?

                  I already provided links to examples several times.

                  "When i do it i get out of index error" - then post your code...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  D 1 Reply Last reply 4 Jan 2021, 12:58
                  0
                  • J jsulm
                    4 Jan 2021, 12:27

                    @suslucoder said in Read data and add it to a chart:

                    And after doing all this things, how can i add my datas to a chart?

                    I already provided links to examples several times.

                    "When i do it i get out of index error" - then post your code...

                    D Offline
                    D Offline
                    deleted286
                    wrote on 4 Jan 2021, 12:58 last edited by
                    #25

                    @jsulm ```
                    QString line = in.readLine();
                    allLines.append(line);
                    QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
                    for(const QString &entry : list) {
                    double num = entry.toDouble();
                    }
                    series->append(num)
                    ``
                    Says use of undeclared identifier num

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 4 Jan 2021, 13:03 last edited by mrjj 1 Apr 2021, 20:00
                      #26

                      Hi
                      You want like

                      QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
                      for(const QString &entry : list) {
                      double num = entry.toDouble();
                      series->append(X,Y);  // use num for either xor y or both depending on what you want
                      }
                      
                      S 1 Reply Last reply 4 Jan 2021, 19:55
                      1
                      • M mrjj
                        4 Jan 2021, 13:03

                        Hi
                        You want like

                        QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
                        for(const QString &entry : list) {
                        double num = entry.toDouble();
                        series->append(X,Y);  // use num for either xor y or both depending on what you want
                        }
                        
                        S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 4 Jan 2021, 19:55 last edited by
                        #27

                        @mrjj said in Read data and add it to a chart:

                        series->append(num); // add each number from the line

                        This cannot work as QLineSeries does not have such an overload.

                        Currently discussed here.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        M 1 Reply Last reply 4 Jan 2021, 19:59
                        1
                        • S SGaist
                          4 Jan 2021, 19:55

                          @mrjj said in Read data and add it to a chart:

                          series->append(num); // add each number from the line

                          This cannot work as QLineSeries does not have such an overload.

                          Currently discussed here.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 4 Jan 2021, 19:59 last edited by mrjj 1 Apr 2021, 20:00
                          #28

                          @SGaist
                          Good catch.
                          yes its x,y.
                          It was more about num being undeclared at that point in time :)
                          Changed as not to confuse future readers.

                          1 Reply Last reply
                          0

                          26/28

                          4 Jan 2021, 13:03

                          • Login

                          • Login or register to search.
                          26 out of 28
                          • First post
                            26/28
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved