@@ -1,173 +1,189 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | import QmlCustomModel 1.0 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | anchors.fill: parent |
|
27 | 27 | |
|
28 | 28 | //![1] |
|
29 | 29 | ChartView { |
|
30 | 30 | id: chartView |
|
31 | 31 | title: "Top-5 car brand shares in Finland" |
|
32 | 32 | anchors.fill: parent |
|
33 | 33 | animationOptions: ChartView.SeriesAnimations |
|
34 | 34 | |
|
35 | 35 | BarCategoriesAxis { |
|
36 | 36 | id: categoryAxis |
|
37 | 37 | categories: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | ValuesAxis { |
|
41 | id: xAxis | |
|
42 | min: 0 | |
|
43 | max: 6.5 | |
|
44 | } | |
|
45 | ValuesAxis { | |
|
41 | 46 | id: yAxis |
|
42 | 47 | min: 0 |
|
43 | 48 | max: 60 |
|
44 | 49 | } |
|
45 | 50 | // ... |
|
46 | 51 | //![1] |
|
47 | 52 | |
|
48 | 53 | //![2] |
|
49 | 54 | CustomModel { |
|
50 | 55 | id: customModel |
|
51 | 56 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] |
|
52 | 57 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } |
|
53 | 58 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } |
|
54 | 59 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } |
|
55 | 60 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } |
|
56 | 61 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } |
|
57 | 62 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } |
|
58 | 63 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } |
|
59 | 64 | } |
|
60 | 65 | //![2] |
|
61 | 66 | |
|
62 | 67 | //![5] |
|
63 | 68 | BarSeries { |
|
64 | 69 | id: myBarSeries |
|
65 | 70 | name: "Others" |
|
66 | 71 | barWidth: 0.9 |
|
67 | 72 | visible: false |
|
68 | 73 | HBarModelMapper { |
|
69 | 74 | model: customModel |
|
70 | 75 | firstBarSetRow: 6 |
|
71 | 76 | lastBarSetRow: 6 |
|
72 | 77 | firstColumn: 2 |
|
73 | 78 | } |
|
74 | 79 | } |
|
75 | 80 | //![5] |
|
76 | 81 | |
|
77 | 82 | //![4] |
|
78 | 83 | LineSeries { |
|
79 | 84 | id: lineSeries1 |
|
80 | 85 | name: "Volkswagen" |
|
81 | 86 | visible: false |
|
82 | 87 | HXYModelMapper { |
|
83 | 88 | model: customModel |
|
84 | 89 | xRow: 0 |
|
85 | 90 | yRow: 1 |
|
86 | 91 | firstColumn: 2 |
|
87 | 92 | } |
|
88 | 93 | } |
|
89 | 94 | //![4] |
|
90 | 95 | |
|
91 | 96 | LineSeries { |
|
92 | 97 | id: lineSeries2 |
|
93 | 98 | name: "Toyota" |
|
94 | 99 | visible: false |
|
95 | 100 | HXYModelMapper { |
|
96 | 101 | model: customModel |
|
97 | 102 | xRow: 0 |
|
98 | 103 | yRow: 2 |
|
99 | 104 | firstColumn: 2 |
|
100 | 105 | } |
|
101 | 106 | } |
|
102 | 107 | |
|
103 | 108 | LineSeries { |
|
104 | 109 | id: lineSeries3 |
|
105 | 110 | name: "Ford" |
|
106 | 111 | visible: false |
|
107 | 112 | HXYModelMapper { |
|
108 | 113 | model: customModel |
|
109 | 114 | xRow: 0 |
|
110 | 115 | yRow: 3 |
|
111 | 116 | firstColumn: 2 |
|
112 | 117 | } |
|
113 | 118 | } |
|
114 | 119 | |
|
115 | 120 | LineSeries { |
|
116 | 121 | id: lineSeries4 |
|
117 | 122 | name: "Skoda" |
|
118 | 123 | visible: false |
|
119 | 124 | HXYModelMapper { |
|
120 | 125 | model: customModel |
|
121 | 126 | xRow: 0 |
|
122 | 127 | yRow: 4 |
|
123 | 128 | firstColumn: 2 |
|
124 | 129 | } |
|
125 | 130 | } |
|
126 | 131 | |
|
127 | 132 | LineSeries { |
|
128 | 133 | id: lineSeries5 |
|
129 | 134 | name: "Volvo" |
|
130 | 135 | visible: false |
|
131 | 136 | HXYModelMapper { |
|
132 | 137 | model: customModel |
|
133 | 138 | xRow: 0 |
|
134 | 139 | yRow: 5 |
|
135 | 140 | firstColumn: 2 |
|
136 | 141 | } |
|
137 | 142 | } |
|
138 | 143 | |
|
139 | 144 | //![3] |
|
140 | 145 | PieSeries { |
|
141 | 146 | id: pieSeries |
|
142 | 147 | size: 0.4 |
|
143 | 148 | horizontalPosition: 0.85 |
|
144 | 149 | verticalPosition: 0.4 |
|
145 | 150 | onClicked: { |
|
146 | 151 | // Show the selection by exploding the slice |
|
147 | 152 | slice.exploded = !slice.exploded; |
|
148 | 153 | |
|
149 | 154 | // Update the line series to show the yearly data for this slice |
|
150 | 155 | for (var i = 0; i < chartView.count; i++) { |
|
151 | 156 | if (chartView.series(i).name == slice.label) { |
|
152 | 157 | chartView.series(i).visible = slice.exploded; |
|
153 | 158 | } |
|
154 | 159 | } |
|
155 | 160 | } |
|
156 | 161 | |
|
157 | 162 | VPieModelMapper { |
|
158 | 163 | model: customModel |
|
159 | 164 | labelsColumn: 1 |
|
160 | 165 | valuesColumn: 2 |
|
161 | 166 | firstRow: 1 |
|
162 | 167 | } |
|
163 | 168 | } |
|
164 | 169 | //![3] |
|
165 | 170 | |
|
166 | 171 | Component.onCompleted: { |
|
167 | createDefaultAxes(); | |
|
168 |
|
|
|
169 | categoryAxis.min = "2007" | |
|
170 | categoryAxis.max = "2014" | |
|
172 | setAxisX(categoryAxis,myBarSeries) | |
|
173 | setAxisX(xAxis,lineSeries1) | |
|
174 | setAxisX(xAxis,lineSeries2) | |
|
175 | setAxisX(xAxis,lineSeries3) | |
|
176 | setAxisX(xAxis,lineSeries4) | |
|
177 | setAxisX(xAxis,lineSeries5) | |
|
178 | setAxisY(yAxis,myBarSeries) | |
|
179 | setAxisY(yAxis,lineSeries1) | |
|
180 | setAxisY(yAxis,lineSeries2) | |
|
181 | setAxisY(yAxis,lineSeries3) | |
|
182 | setAxisY(yAxis,lineSeries4) | |
|
183 | setAxisY(yAxis,lineSeries5) | |
|
184 | categoryAxis.min = "2007" | |
|
185 | categoryAxis.max = "2014" | |
|
186 | categoryAxis.visible = true; | |
|
171 | 187 | } |
|
172 | 188 | } |
|
173 | 189 | } |
General Comments 0
You need to be logged in to leave comments.
Login now