1

我有一系列大约 722 个值的数据,我想使用 qml 和 cpp 绘制这些数据。如何动态更改折线图的 x 和 y 轴的值?以及如何附加数据?

我浏览了示波器示例,但它使用查看器,并且我正在为已经制作的 GUI 编写代码,可以请帮助我吗?

QML部分:

    import QtQuick 2.0
    import QtCharts 2.0
    import QtQml 2.2

    Item {
        id: valueDisp
        implicitWidth: 640
        implicitHeight: 640
        property int currentIndex: -1

        ChartView {
            id: chartView
            title: "Data Output"
            anchors.fill: parent
            legend.visible: false
            antialiasing: true
        }

        Timer {
            id: refreshTimer
            interval: 500 // 60 Hz
            running: componentData.dataUpdated();
            repeat: true
            onTriggered: {
                var lineSeries = chartView.series("Data Output")
                //var x_limit= componentData.dataReadX(currentIndex)
                var i = 0
                console.log("currentIndex;: " + currentIndex)
                if (currentIndex <= 0) {
                    lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, "Data Output")
                    chartView.axisY().min = 0;
                    chartView.axisY().max = 100;
                    chartView.axisX().min = 0;
                    chartView.axisX().max = 100;
                    chartView.axisY().tickCount = 6;
                    chartView.axisY().titleText = "value";
                    chartView.axisX().titleText = "Iteration";
                    chartView.axisX().labelFormat = "%.0f";
                    currentIndex++;
                }

                lineSeries.append(componentData.dataReadX(currentIndex), componentData.dataReadY(currentIndex));
                currentIndex++;

            }
        }
    }

PS-componentData是访问我的 cpp Q_INVOKABLE 函数的对象。我想出了如何传递数据,但我坚持激活计时器如果是的话,它是否也需要 OpenGL,那么我该如何激活它?

4

0 回答 0