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. Real time Plotting Line chart
QtWS25 Last Chance

Real time Plotting Line chart

Scheduled Pinned Locked Moved Solved General and Desktop
qtchartsqtlineseriesqt5.9.1real time plotubuntu 16.04
8 Posts 6 Posters 11.9k 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.
  • A Offline
    A Offline
    Andrex_Qt
    wrote on last edited by Christian Ehrlicher
    #1

    Hello,
    i am trying to make a line chart which updates after 1 sec or less, I feed data from SPI to my Line chart 4 points at a time.
    I am following the QLinechart example in creator and to update the graph I have used timeout() of a Qtimer to call updater() function does oly chartView.update();
    but I always get segmentation Plot.
    I am doing this right?is there a better method?

    code snippet as follows:

    MainWindow
    {
     ui->setupUi(this);
    
    //-----SPI initialization-----------
    
     t1 = new  QTimer(this);
     connect(t1,SIGNAL (timeout()),this,SLOT(spi()));
     t1->start(0);
    
     t2 = new  QTimer(this);
     connect(t2,SIGNAL (timeout()),this,SLOT(updater()));
     t2->start(1000);
    
    //-----chan[4] data from SPI----
    
      QLineSeries *series = new QLineSeries();
    *series  <<QPointF(0,chan[0])  << QPointF(1,chan[1]) << QPointF(2,chan[2]) <<QPointF(3,chan[3]);
    
     QChart *chart = new QChart();
     chart->legend()->hide();
     chart->addSeries(series);
     chart->createDefaultAxes();
     //chart->setAxisX(0,series);
     chart->setTitle("Simple line chart example");
    
     QChartView *chartView = new QChartView(chart);
     chartView->setRenderHint(QPainter::Antialiasing);
     chartView->setParent(ui->verticalFrame);
    
    }
    
    void MainWindow::spi()
    {
     //----Get SPI data----------
    }
    
    
    void MainWindow::updater()
    {
     //chartView->repaint();
    chartView->update();
    
    }
    
    1 Reply Last reply
    0
    • W Offline
      W Offline
      wincak
      wrote on last edited by
      #2

      If you don't mind using a library you can try QCustomPlot.

      The Axis tags example shows how to create a periodically updating (40 ms) chart.

      A 1 Reply Last reply
      3
      • W wincak

        If you don't mind using a library you can try QCustomPlot.

        The Axis tags example shows how to create a periodically updating (40 ms) chart.

        A Offline
        A Offline
        Andrex_Qt
        wrote on last edited by
        #3

        @wincak
        thanks for the suggestion, I tried it and it works good.
        I have two questions:
        It doesn't seem to have Pie-Chart, can you confirm?
        and is this library free?

        Pl45m4P 1 Reply Last reply
        0
        • A Andrex_Qt

          @wincak
          thanks for the suggestion, I tried it and it works good.
          I have two questions:
          It doesn't seem to have Pie-Chart, can you confirm?
          and is this library free?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @Andrex_Qt said in Real time Plotting Line chart:

          It doesn't seem to have Pie-Chart, can you confirm?

          Yes, true. There is no pie-chart as such.

          @Andrex_Qt said in Real time Plotting Line chart:

          is this library free

          QCustomPlot was released under GPL license and is free to use in free software.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          L 1 Reply Last reply
          2
          • A Offline
            A Offline
            asterixxx
            wrote on last edited by
            #5

            https://www.youtube.com/watch?v=lXXUxy5Opds&t=2s

            1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @Andrex_Qt said in Real time Plotting Line chart:

              It doesn't seem to have Pie-Chart, can you confirm?

              Yes, true. There is no pie-chart as such.

              @Andrex_Qt said in Real time Plotting Line chart:

              is this library free

              QCustomPlot was released under GPL license and is free to use in free software.

              L Offline
              L Offline
              lira
              wrote on last edited by
              #6

              @Pl45m4 is QCustomPlot only for Linux?

              mrjjM 1 Reply Last reply
              0
              • L lira

                @Pl45m4 is QCustomPlot only for Linux?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @lira
                Hi and welcome to the forums.
                No, it will run most places that Qt can.
                It's just a .h and .cpp file you include in your project so it will work on most platforms.

                L 1 Reply Last reply
                2
                • mrjjM mrjj

                  @lira
                  Hi and welcome to the forums.
                  No, it will run most places that Qt can.
                  It's just a .h and .cpp file you include in your project so it will work on most platforms.

                  L Offline
                  L Offline
                  lira
                  wrote on last edited by
                  #8

                  @mrjj thank you :)

                  1 Reply Last reply
                  0

                  • Login

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