| 1 |
// Copyright (C) 2023 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
import QtCharts |
| 5 |
|
| 6 |
//![1] |
| 7 |
ChartView { |
| 8 |
id: root |
| 9 |
title: "Accurate Historical Data" |
| 10 |
anchors.fill: parent |
| 11 |
legend.visible: false |
| 12 |
antialiasing: true |
| 13 |
|
| 14 |
LineSeries { |
| 15 |
axisX: DateTimeAxis { |
| 16 |
format: "yyyy MMM" |
| 17 |
tickCount: 5 |
| 18 |
} |
| 19 |
axisY: ValueAxis { |
| 20 |
min: 0 |
| 21 |
max: 150 |
| 22 |
} |
| 23 |
|
| 24 |
// Please note that month in JavaScript months are zero based, so 2 means March |
| 25 |
XYPoint { x: root.toMsecsSinceEpoch(new Date(1950, 2, 15)); y: 5 } |
| 26 |
XYPoint { x: root.toMsecsSinceEpoch(new Date(1970, 0, 1)); y: 50 } |
| 27 |
XYPoint { x: root.toMsecsSinceEpoch(new Date(1987, 12, 31)); y: 102 } |
| 28 |
XYPoint { x: root.toMsecsSinceEpoch(new Date(1998, 7, 1)); y: 100 } |
| 29 |
XYPoint { x: root.toMsecsSinceEpoch(new Date(2012, 8, 2)); y: 110 } |
| 30 |
} |
| 31 |
|
| 32 |
// DateTimeAxis is based on QDateTimes so we must convert our JavaScript dates to |
| 33 |
// milliseconds since epoch to make them match the DateTimeAxis values |
| 34 |
function toMsecsSinceEpoch(date) { |
| 35 |
var msecs = date.getTime(); |
| 36 |
return msecs; |
| 37 |
} |
| 38 |
} |
| 39 |
//![1] |