Unsolved Implementing real time plot with Qt5 charts
-
Hello,
I am new to Qt and trying to implement a real time plot using QSplineSeries with Qt 5.7. I need to scroll the x axis as new data comes in every 100ms. It seems the CPU usage reaches 100% if I do not purge the old data which was appended to the series, using graphSeriesX->remove(0). I found two ways of scrolling the x axis.
const uint8_t X_RANGE_COUNT = 50; const uint8_t X_RANGE_MAX = X_RANGE_COUNT - 1; qreal y = (axisX->max() - axisX->min()) / axisX->tickCount(); m_x += y; if (m_x > axisX->max()) { axisX->setMax(m_x); axisX->setMin(m_x - 100); } if (graphSeries1->count() > X_RANGE_COUNT) { graphSeries1->remove(0); graphSeries2->remove(0); graphSeries3->remove(0); }
The problem with the above is that m_x is of type qreal and at some time if I keep the demo running continuously, it will reach it's MAX value and the axisX->setMax call will fail making the plot not work anymore. What would be the correct way to fix this use case?
- In the second method I use scroll as
qreal x = plotArea().width() / X_RANGE_MAX; chart->scroll(x, 0) if (graphSeries1->count() > X_RANGE_COUNT) { graphSeries1->remove(0); graphSeries2->remove(0); graphSeries3->remove(0); }
However it's not clear to me how can I use the graphSeriesX->remove(0) call in this scenario. The graph will keep getting wiped out since once the series get appended with X_RANGE_COUNT values, the if block will always be true removing 0th value but the scroll somehow does not work the way manually setting maximum for x axis works and after a while I have no graph. scroll works if I do not call remove but then my CPU usage reaches 100%.
Can someone point me in the right direction?
Regards,
Sanchayan.