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}
}
}
}