main.qml Example File
qmlf1legends/qml/qmlf1legends/main.qml
import QtQuick 2.0
import QtCharts 2.0
import QtQuick.XmlListModel 2.0
Item {
width: 400
height: 300
property int currentIndex: -1
ChartView {
id: chartView
title: "Driver Speeds, lap 1"
anchors.fill: parent
legend.alignment: Qt.AlignTop
animationOptions: ChartView.SeriesAnimations
antialiasing: true
}
SpeedsXml {
id: speedsXml
onStatusChanged: {
if (status == XmlListModel.Ready) {
timer.start();
}
}
}
Timer {
id: timer
interval: 700
repeat: true
triggeredOnStart: true
running: false
onTriggered: {
currentIndex++;
if (currentIndex < speedsXml.count) {
var lineSeries = chartView.series(speedsXml.get(currentIndex).driver);
if (!lineSeries) {
lineSeries = chartView.createSeries(ChartView.SeriesTypeLine,
speedsXml.get(currentIndex).driver);
chartView.axisY().min = 0;
chartView.axisY().max = 250;
chartView.axisY().tickCount = 6;
chartView.axisY().titleText = "speed (kph)";
chartView.axisX().titleText = "speed trap";
chartView.axisX().labelFormat = "%.0f";
}
lineSeries.append(speedsXml.get(currentIndex).speedTrap,
speedsXml.get(currentIndex).speed);
if (speedsXml.get(currentIndex).speedTrap > 3) {
chartView.axisX().max = Number(speedsXml.get(currentIndex).speedTrap) + 1;
chartView.axisX().min = chartView.axisX().max - 5;
} else {
chartView.axisX().max = 5;
chartView.axisX().min = 0;
}
chartView.axisX().tickCount = chartView.axisX().max - chartView.axisX().min + 1;
} else {
timer.stop();
chartView.animationOptions = ChartView.AllAnimations;
chartView.axisX().min = 0;
chartView.axisX().max = speedsXml.get(currentIndex - 1).speedTrap;
}
}
}
}