Real time Plotting Line chart
-
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(); }
-
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.
-
@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.
-