qt qml 图表显示

在chartview 显示带时间刻度的曲线

qt qml 图表显示_第1张图片

源码

import QtQuick 2.10
import QtQuick.Window 2.10
import QtCharts 2.0
Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    ChartView
    {
        anchors.fill: parent
        id:chart
        DateTimeAxis
        {
            format: "yyyy-MM-dd HH:mm mm:ss"; //"yyyy MMM dd";HH:mm mm:ss
            id:thex
         //   tickCount: 6
        }
        ValueAxis
        {
            max: 1
            min: -1
            id:theY
        }
 
        LineSeries
        {
            name:"测试"
            axisX: thex
            axisY: theY
        }
 
 
    }
    Component.onCompleted:
    {
 
        var p = Math.PI/512;
 
        var t = new Date();
        thex.min = t;
        var t2 = new Date();
        t2.setHours(t2.getHours()+1024);
        thex.max = t2;
 
 
        for(var i = 0; i< 1024; i++)
        {
            t.setHours(t.getHours() + 1);
 
            chart.series(0).append(t.getTime(),Math.sin( i*p));
        }
 
    }
}

你可能感兴趣的:(qt qml 图表显示)