QML Graphs using dynamic data (from C++)
Unsolved
QML and Qt Quick
-
I am trying to use QtGraphs to display an area chart of elevation data from a cycling trip. I have the data ready in C++ and am looking for a way to expose it to QML. I have been scouring the Qt docs for an explanation but every example seems to use the XYPoint classes with static data like the following:
// Code that works but uses static data GraphsView { height: 500 width: parent.width axisX: ValueAxis { max: 3 } axisY: ValueAxis { max: 3 } AreaSeries { color: "blue" upperSeries: LineSeries { XYPoint { x: 0.5; y: 0.5 } XYPoint { x: 1; y: 1 } XYPoint { x: 2; y: 2 } XYPoint { x: 2.5; y: 1.5 } } } }
I would ideally like to do something like this instead:
// Code that does not work but uses dynamic data instead GraphsView { height: 500 width: parent.width axisX: ValueAxis { max: 3 } axisY: ValueAxis { max: 3 } AreaSeries { color: "blue" upperSeries: elevationData } }
...where elevationData is something like a QVariantMap or QStringList from C++ side. This way, if elevationData changes, the graph will change. Any ideas?
-
Use a
XYModelMapper
in combination of aQAbstractItemModel
.