Getting data into QML ChartView with Repeater
-
Hi everyone,
I'm having problems getting data from my model which is a QList<QPointF> into the LineSeries of my ChartView in QML.
The QML code looks like this:
ChartView { Layout.fillWidth: true Layout.fillHeight: true legend.visible: false backgroundColor: "#aaa" backgroundRoundness: 0.0 margins.top: 0 margins.bottom: 0 margins.left: 0 margins.right: 0 LineSeries { color: "#f00" width: 1 useOpenGL: true axisX: ValueAxis { visible: false min: 0.0 max: 1.0 } axisY: ValueAxis { visible: false min: 0.0 max: 1.0 } Repeater { model: itemModel.chartPoints delegate: XYPoint { x: model.x y: model.y Component.onCompleted: { console.log("XYPoint completed") } } Component.onCompleted: { console.log("Repeater completed - model size: " + model.length + " example point: " + model[2]) } } // XYPoint { x: 0.1; y: 0.5 } // XYPoint { x: 0.2; y: 0.4 } // XYPoint { x: 0.3; y: 0.7 } } }
From C++ I provide this QList of QPointF for testing purposes:
const QList<QPointF>& StockItem::chartPoints() const { static QList<QPointF> test; if (test.isEmpty()) { test.emplace_back(QPointF(0.1, 0.5)); test.emplace_back(QPointF(0.2, 0.4)); test.emplace_back(QPointF(0.3, 0.7)); } return test; }
I'm getting this output from the onCompleted event of the Repeater:
qml: Repeater completed - model size: 4 example point: QPointF(0.4, 0.3)
So the model is correctly assigned and the data is available. But I don't get outputs from onCompleted events of XYPoint and the chart remains empty.
If I uncomment this code to add points manually the lines are drawn correctly:XYPoint { x: 0.1; y: 0.5 } XYPoint { x: 0.2; y: 0.4 } XYPoint { x: 0.3; y: 0.7 }
What am I missing here?
I also tried using the ShapePath component with PathLine elements before since I just need a minimal data graph without legends and axes and all that stuff. But there I cannot use a Repeater at all to add points to the line.
Thank you in advance for any help!
Daniel -
Nevermind, I implemented my own QQuickItem which uses the QML scene graph, following this example:
https://doc.qt.io/qt-5/qtquick-scenegraph-customgeometry-example.html