Solved ValueAxis QML Type, Y axis Auto Fit!!
-
I had a dynamic chart now! with QML
But how to make the ValueAxis (for y axis) to automatically fit the the plotted data through ChartView!
I tried to get the chart data and store it in an array, then check the max and min inside the array, but it looks complicated for me and I can't even look inside the array!
Any advice!
-
Hi,
Probably You may use
scale
prop for it.
Just track lowest and highest values as they come in real time and when a span between them changes - adjust the scale. -
Check the solution given in the following link
https://stackoverflow.com/questions/44940190/qtcharts-auto-range-for-y-axis
P.S. Chart is created using Cpp. -
Hi,
Why don't you use the following example?
https://forum.qt.io/topic/77439/can-someone-provide-a-working-example-of-vxymodelmapper-with-lineseries-chart/2void ChartModel::appendData(double const xVal,double const yVal) { setXMin(qMin(m_xMin, xVal)); setXMax(qMax(m_xMax, xVal)); setYMin(qMin(m_yMin, yVal)); setYMax(qMax(m_yMax, yVal)); int const vecSize = vecChartPoints.size(); beginInsertRows(QModelIndex (), vecSize, vecSize); vecChartPoints.append(qMakePair<double, double>(xVal, yVal)); endInsertRows(); }
ValueAxis { id: valueAxisY min: chartModel.yMin max: chartModel.yMax labelFormat: "%.2f" }