qml chartView

import QtQuick 2.14
import QtQuick.Window 2.14
import QtCharts 2.14

import QtQuick.Controls 1.4

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")


    property real _timer: 1

    Button {
        id: _tir

        width: 100
        height: 20

        text: "Add Points"

        onClicked: {

            _lineSeries.append(_timer,Math.random()*200 + 10)
            _timer = _timer+1
            console.log("_timer: ", _timer)
        }
    }

    Button {

        id: _clear

        x: _tir.width + 20
        width: 100
        height: 20

        text: "Clear Points"

        onClicked: {
            for(var i = _timer; i > 0; i--)
            {
                console.log("i = ", i)
                _lineSeries.remove(i - 1);
            }
            _timer = 1;
        }
    }

    ChartView {
        anchors.top: _tir.bottom
        anchors.topMargin: 10


        anchors.left: parent.left
        anchors.leftMargin: 10
        anchors.right: parent.right
        anchors.rightMargin: 10
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 10

        antialiasing: true
        legend.alignment: Qt.AlignBottom
        legend.visible: false

        // 背景s色
        backgroundColor: "gray"

        // 动画
        animationOptions: ChartView.SeriesAnimations

        margins.left: 10
        margins.right: 10
        margins.top: 10
        margins.bottom: 10

        ValueAxis {
            id: _axisX

            min: 0
            max: 3 > _timer ? 3 : _timer

            // 轴上的刻度数
            tickCount: 3 > _timer ? 3 : _timer

            // 轴上的次刻度标记数量
            //            minorTickCount: 10
            minorTickCount: 10
            tickInterval : ValueAxis.TicksFixed

            labelFormat: '%d'
            labelsColor: "white"
            labelsFont.bold: true
            labelsFont.pointSize: 13
        }

        ValueAxis {
            id: _axisY

            min: 0
            max: 300

            // 轴上的刻度数
            tickCount: 10

            // 轴上的次刻度标记数量
            minorTickCount: 10
            tickInterval : ValueAxis.TicksFixed

            labelFormat: '%d'
            labelsColor: "white"
            labelsFont.bold: true
            labelsFont.pointSize: 13

        }
        LineSeries {
            id: _lineSeries
            name: "LineSeries"
            axisX: _axisX
            axisY: _axisY
            width: 4
            capStyle: Qt.RoundCap
            style: Qt.DotLine
            color: Qt.rgba(0.6, 0, 1, 1)

            XYPoint {x: 0; y: 0}

        }
    }



}

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值