QCustomPlot Discussion and Comments

Real-time data plottingReturn to overview

http://www.qcustomplot.com/images/examples/realtimedatademo.png

First, I'd like to give a shout out to the developer of this library (Emanuel Eichhammer), you are awesome :), I love this library - I've been having problems with easy data visualization recently, but you solved them. Secondly, I have a question regarding real-time data plotting.

I have simulations running, and I have an interface that plots the results of the simulation in real-time. The adding of data to the plot currently goes as follows:

1) Add data
2) Rescale axis (if necassary)
3) call 'replot()' to show effect

The 'replot()' is slowing down my simulations. I am sure there is a better way of doing this, and I'd really appreciate some help.

Thanks :)

Your way is correct and That's not suppose to be slow!!! how many data and graphs you have used?
The real time example is pretty light and quick :)

As for rescale step, try to avoid it if possible. I've found it much more effective to change axes ranges manually using only the last added point.

How do you change the rescale axis manually ?

Mohd, screen shows blank graph with data curve, appearing along the time axis. When the plot border reached, range is changed to show next time period and data curve filling it again.
This method is often shown in hospital ECG monitors.

Mohd, I call QCPAxis::setRangeUpper() with x or y of new point being added.

Hi sairus777,

I'm aware that setting a new range then requires setRange if i'm not wrong but how do you then get the current max range of say, the x-axis?

I think it's for example:
ui->rawGraph->xAxis->range().lower

As an aside, I think it would be very useful if there were methods to: a) only rescale one axis but not both, b) only rescale to zoom out but not in.

By Add data you mean adding new data to previously existing data or actually replacing it?
In the real-time demos data is actually replaced at each drawing. If you instead add new data QCP would still have to iterate through all the data (even if it's not visible on the graph), and this might be why your graph is slowing down.

Data points that are not visible on the screen (e.g. scrolled out to the left or right of the x axis range) can be handled extremely fast due to the way QCustomPlot stores the data. You can have millions of points outside the visible range without significant slowdown of the replot rate.

Although adding data (addData) should be preferred if possible, even re-setting the data points entirely with setData is quite fast, compared to the time that is needed to actually draw the plot. Have a look at the performance improvement tweaks at the bottom of the documentation start page.