QT QML realtime chart
-
Hi this my code which is working file. It takes data from C++ "valfromCpluplus" and plot on the chart.
My concern is whether this approach is fine or not. Because my application may be running for days and increment of "yval" and "scrolleft()" is bothering me.
Because after sometime yval and scrolleft will reach their max limit and then there may be unknown situations in the application.
I want to maintain the history of around 200 updates on chart and new entry will remove the oldest and the hart will be kept on scrolling with new values.
import QtQuick 2.0 import QtCharts 2.0 Item { anchors.fill: parent property int valfromCplusplus: 0 propery LineSeries series: NULL property int yval:0 Text{ id:txt text: valfromCplusplus onTextChanged{ yval++; chart.series(0).append(valfromCplusplus,yval); if(yval >200) { chart.series(0).remove(); chart.scrolleft(1); } } } ChartView { title: chart anchors.fill: parent legend.visible: false antialiasing: true ValueAxis { id: axisX } ValueAxis { id: axisY } component.onComplete{ series = chart.createSeries(ChartView.SeriesLineSeries, "Line", axisX, axisY); } }
Please ignore if there is any mistake in the code because i have running code similar to this. Please consider it as a pseudo code(algo) and suggest some suitable solution how i can achieve the intended goal without uncertainties.
-
@vicky_mac the highest number
int
can become in qml is 2^31 - 1 aka 2147483647, if you increment your int every second, you will have an integer overflow after roughly 68 years.so I think you will be fine.