I want to plot data in Qt charts (QML) from python. The x,y data are saved in array x = np.array([0, 6]) y = np.array([0, 250]) . I am desperate how to pass these data to Qt Charts with one step. I can do it (step by step) with Signal/Slot, where the Signal is with parameters (x,y).
My working (very slow) code:
Creating signal from python to qml:
class AppWindow(QObject):
# Signals from python to QML
sigPlotData = Signal(int, int, arguments=['x','y'])
and later () I generate and send data to chart like that:
...
for i in range(50):
self.app.sigPlotData.emit(i, random.randint(0,150))
...
In QML file I do this:
//connections from Python to QML via signals
Connections {
target: backend
function onSigPlotData(x,y){
lineSer.append(x, y);
}
}
ChartView {
id: chartView
title: "Line"
anchors.fill: parent
ValueAxis{
id: axisX
min: 0
max: maxX
}
ValueAxis{
id: axisY
min: 0
max: 150
}
LineSeries {
id: lineSer
name: "data"
axisX: axisX
axisY: axisY
}
}
Thank you very much for help.
you can have this :
in main.py :
and in
main.qml:Result is:
In QML you can create your function or other things like(for, if,..) with javascript syntax
and as you see I use
series1.append(timeStep, y);means append function for adding data.