Qt Chart is not updated after updating the series
-
I don't see the new point out of bounds of your axis so that is good. From what I understand when appending the series you should be good as long as it is the pointer to the correct series. Assuming the discrepancy for scatter series and line series is an artifact of you swapping between line and scatter series for troubleshooting, are you constantly running something without allowing the event handler to process? Try adding QApplication::processEvents(); after your repaint.
-
-
@MrShawn . You are right, you once suggested. Maybe the only updating the series did not update the pointer .I am not sure thought. But his fixed the problem. Every time I update the series, I have to remove the series and again add the series. I do not understand why is like this.
chart->removeSeries(scatterseries); chart->addSeries(scatterseries);
-
I think on my first code I wrote for Charts I did a similar thing. As I got used to QCharts and how things were working I stopped doing that. Looking back at some code I do recently, where I pull data from DB and populate the series from that data. I can confirm that you should not have to do that. That is why my suspicion is that the series you were appending is not truly on the chart, and by adding that code it does now actually add it.
Anyways if it works it works.
-
@MrShawn . Yes it works now. I am wondering what could be the better way instead of removing and adding series again and again. I can think only other way to be to create new class inheriting QCharts and create series as a class member of the class.
-
seen https://doc.qt.io/qt-5/qxyseries.html#replace-5 ?
even if you are doing it just for one point - by destroying and creating a series over and over you do this anyhow. has to be quicker/better.
I belive that also invokes
https://doc.qt.io/qt-5/qxyseries.html#pointsReplacedChartView should handle redraw and everything for you.
-