Debian Codegraph @

examples/charts/qmlchartsgallery/qml/customlegend/ChartViewHighlighted.qml

raw
1 // Copyright (C) 2023 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4 import QtQuick
5 import QtCharts
6
7 //![1]
8 ChartView {
9 id: chartViewHighlighted
10
11 property variant selectedSeries
12
13 signal clicked
14
15 legend.visible: false
16 margins.top: 10
17 margins.bottom: 0
18 antialiasing: true
19
20 LineSeries {
21 id: lineSeries
22
23 axisX: ValueAxis {
24 min: 2006
25 max: 2012
26 labelFormat: "%.0f"
27 tickCount: 7
28 }
29 axisY: ValueAxis {
30 id: axisY
31 titleText: "EUR"
32 min: 0
33 max: 40000
34 labelFormat: "%.0f"
35 tickCount: 5
36 }
37 }
38 //![1]
39
40 MouseArea {
41 anchors.fill: parent
42 onClicked: {
43 chartViewHighlighted.clicked();
44 }
45 }
46
47 onSelectedSeriesChanged: {
48 lineSeries.clear();
49 lineSeries.color = selectedSeries.color;
50 var maxVal = 0.0;
51 for (var i = 0; i < selectedSeries.upperSeries.count; i++) {
52 var y = selectedSeries.upperSeries.at(i).y - selectedSeries.lowerSeries.at(i).y;
53 lineSeries.append(selectedSeries.upperSeries.at(i).x, y);
54 if (maxVal < y)
55 maxVal = y;
56 }
57 chartViewHighlighted.title = selectedSeries.name;
58 axisY.max = maxVal;
59 axisY.applyNiceNumbers()
60 }
61 }
62