I want to draw a plot of sensor data that is saved in a QList. I know that getting the data up to the qml level works fine, because it correctly prints to console (see code).
My question now is, how can I draw a LineChart out of this data? I tried a repeater and some sketchy for- loops but none seem to work and only an empty chart is displayed.
As stated above, the data works and is logged correctly. The axis are correct as well, there just is no line.
My most promising try:
import QtQuick 2.0
import QtCharts 2.3
Item {
width:400
height:600
ChartView
{
width:parent.width
height:parent.height
Component.onCompleted: {
//Data displayed correctly
console.log(device.AIN3data.length);
console.log(device.AIN3data)
}
ValueAxis {
id: axisX
min: 0
max: device.AIN3data.length
}
ValueAxis {
id: axisY
min: 0
max: 1000
}
LineSeries
{
axisX: axisX
axisY:axisY
name: "AIN3"
Repeater
{
model: device.AIN3data.length
XYPoint{x:index;y:device.AIN3data[index]}
Component.onCompleted: console.log("Repeater")
}
}
}
}
Repeater is used to generate several Items, not for XYPoint. In this case it is better to create a C++ model, export it to QML and then map to a LineSeries using VXYModelMapper.