QCustomPlot Discussion and Comments

Performance in Realtime plottingReturn to overview

Hi there!

I have a realtime plot with 4 graphs and with a ton of data. The vectors get sent to the plot every ~5 sec.
Currently, I am plotting a total of 20 seconds by removing the oldest 5 sec from the plot with removeBefore.
I tested the code with addData and withsetData, but both result in a total of about 600ms to plot. There is no difference in perfomance whether I use add or set Data which I find surprinsing. renew_plot_data is called every 5 seconds.


renew_plot_data:

    

QElapsedTimer timer;
timer.start();
for(int i=0; i<6; i++)
{        
 if(Active[i])
 {

  actualWidget->graph(i)->setVisible(Active[i]);
  actualWidget->graph(i)->data()->removeBefore(key - (MAX_REPS - 1)* TIME_BASE );
  actualWidget->graph(i)->addData(time, data_plot[InvNum[i]][ParNum[i]]);
  actualWidget->graph(i)->setName(StrNum[i]);
  actualWidget->graph(i)->addToLegend();
 }
}
actualWidget->xAxis->rescale(true);
actualWidget->replot();
qDebug()<< "all in all plot data took " << timer.elapsed() << " ms.";
qDebug() << "end for.";
       


but this results in the same performance (if in both cases only 5sec are shown)


    

QElapsedTimer timer;
timer.start();
for(int i=0; i<6; i++)
{        
 if(Active[i])
 {

  actualWidget->graph(i)->setVisible(Active[i]);
  actualWidget->graph(i)->setData(time, data_plot[InvNum[i]][ParNum[i]]);
  actualWidget->graph(i)->setName(StrNum[i]);
  actualWidget->graph(i)->addToLegend();
 }
}
actualWidget->xAxis->rescale(true);
actualWidget->replot();
qDebug()<< "all in all plot data took " << timer.elapsed() << " ms.";
qDebug() << "end for.";
       

From my understanding, addData should result in a better performance.
I try to reduce the replotting time as during that time the graph cannot be moved neither comboboxes or checkboxes can be clicked, resulting in a feelable lag.


Thank you in advance!
Best

as far as i know, the only difference between addData and setData is that setData has to loop through and set more values. (in your case, 15 extra seconds worth)... but if you dont have a lot of data in that 15 seconds, then the time savings in this case would be negligible.

however, if you had a plot with 1M points and then wanted to add a single point, obviously it would be faster to add 1 point than 1M+1.

The majority of the plotting time is related to calculating the bounds(if you call rescale axes) and the actual drawing time. neither of these are affected by the current implementation of addData or setData.

Thank you Ian!
I made some changes on the order (put some things in front of the for-loop etc) and used the "already sorted" bool of add/set Data and got down to about 25ms/graph. During that time, however, no new data is collected, therefore resulting in a blank space. Thats why I want to minimate the drawing time. It is only max 100ms but still 100ms where no data is collected.
Is it true, that it is not possible to replot the graph outside the GUI thread?

Thank you in advance :)