qtqmlqt5qchartview

QML chartview get X,Y of Lineseries.onPointAdded


How can I get the X and Y of the point added in Lineseries?
This code is placed inside a simple ChartView.

If I have the following:

LineSeries {
        id: data
        name: "name"
        axisX: axisX
        axisY: axisY
        onPointAdded: {
            //retrieve x and y
    }
}

What should replace the comment inside onPointAdded?
Thanks.


Solution

  • The pointAdded signal passes as a parameter the index of the added element, this index must be used next to the method at() to obtain the point:

    onPointAdded: {
        var point = data.at(index);
        console.log(point.x, point.y)
    }