@@ -1,161 +1,184 | |||
|
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 | categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] | |
|
37 | categories: ["2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] | |
|
38 | } | |
|
39 | ||
|
40 | ValuesAxis { | |
|
41 | id: yAxis | |
|
42 | min: 0 | |
|
43 | max: 60 | |
|
38 | 44 | } |
|
39 | 45 | // ... |
|
40 | //![1] | |
|
46 | //![1] | |
|
41 | 47 | |
|
42 | 48 | //![2] |
|
43 | 49 | CustomModel { |
|
44 | 50 | id: customModel |
|
45 | 51 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] |
|
46 | 52 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } |
|
47 | 53 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } |
|
48 | 54 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } |
|
49 | 55 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } |
|
50 | 56 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } |
|
51 | 57 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } |
|
52 | 58 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } |
|
53 | 59 | } |
|
54 | 60 | //![2] |
|
55 | 61 | |
|
56 | 62 | //![5] |
|
57 | 63 | BarSeries { |
|
58 | 64 | id: myBarSeries |
|
59 | 65 | name: "Others" |
|
60 | 66 | barWidth: 0.9 |
|
61 |
|
|
|
67 | visible: false | |
|
62 | 68 |
|
|
63 | 69 | model: customModel |
|
64 | 70 | firstBarSetRow: 6 |
|
65 | 71 | lastBarSetRow: 6 |
|
66 | 72 | firstColumn: 2 |
|
67 | 73 | } |
|
68 | 74 | } |
|
69 | 75 | //![5] |
|
70 | 76 | |
|
71 | 77 | //![4] |
|
72 | 78 | LineSeries { |
|
79 | id: lineSeries1 | |
|
73 | 80 | name: "Volkswagen" |
|
74 |
|
|
|
81 | visible: false | |
|
75 | 82 |
|
|
76 | 83 | model: customModel |
|
77 | 84 | xRow: 0 |
|
78 | 85 | yRow: 1 |
|
79 | 86 | firstColumn: 2 |
|
80 | 87 | } |
|
81 | 88 | } |
|
82 | 89 | //![4] |
|
83 | 90 | |
|
84 | 91 | LineSeries { |
|
92 | id: lineSeries2 | |
|
85 | 93 | name: "Toyota" |
|
86 | 94 | visible: false |
|
87 | 95 | HXYModelMapper { |
|
88 | 96 | model: customModel |
|
89 | 97 | xRow: 0 |
|
90 | 98 | yRow: 2 |
|
91 | 99 | firstColumn: 2 |
|
92 | 100 | } |
|
93 | 101 | } |
|
94 | 102 | |
|
95 | 103 | LineSeries { |
|
104 | id: lineSeries3 | |
|
96 | 105 | name: "Ford" |
|
97 | 106 | visible: false |
|
98 | 107 | HXYModelMapper { |
|
99 | 108 | model: customModel |
|
100 | 109 | xRow: 0 |
|
101 | 110 | yRow: 3 |
|
102 | 111 | firstColumn: 2 |
|
103 | 112 | } |
|
104 | 113 | } |
|
105 | 114 | |
|
106 | 115 | LineSeries { |
|
116 | id: lineSeries4 | |
|
107 | 117 | name: "Skoda" |
|
108 | 118 | visible: false |
|
109 | 119 | HXYModelMapper { |
|
110 | 120 | model: customModel |
|
111 | 121 | xRow: 0 |
|
112 | 122 | yRow: 4 |
|
113 | 123 | firstColumn: 2 |
|
114 | 124 | } |
|
115 | 125 | } |
|
116 | 126 | |
|
117 | 127 | LineSeries { |
|
128 | id: lineSeries5 | |
|
118 | 129 | name: "Volvo" |
|
119 | 130 | visible: false |
|
120 | 131 | HXYModelMapper { |
|
121 | 132 | model: customModel |
|
122 | 133 | xRow: 0 |
|
123 | 134 | yRow: 5 |
|
124 | 135 | firstColumn: 2 |
|
125 | 136 | } |
|
126 | 137 | } |
|
127 | 138 | |
|
128 | 139 | //![3] |
|
129 | 140 | PieSeries { |
|
130 | 141 | id: pieSeries |
|
131 | 142 | size: 0.4 |
|
132 |
horizontalPosition: 0. |
|
|
143 | horizontalPosition: 0.85 | |
|
133 | 144 | verticalPosition: 0.4 |
|
134 | 145 | onClicked: { |
|
135 | 146 | // Show the selection by exploding the slice |
|
136 | 147 | slice.exploded = !slice.exploded; |
|
137 | 148 | |
|
138 | 149 | // Update the line series to show the yearly data for this slice |
|
139 | 150 | for (var i = 0; i < chartView.count; i++) { |
|
140 | 151 | if (chartView.series(i).name == slice.label) { |
|
141 | 152 | chartView.series(i).visible = slice.exploded; |
|
142 | 153 | } |
|
143 | 154 | } |
|
144 | 155 | } |
|
156 | ||
|
157 | VPieModelMapper { | |
|
158 | model: customModel | |
|
159 | labelsColumn: 1 | |
|
160 | valuesColumn: 2 | |
|
161 | firstRow: 1 | |
|
162 | } | |
|
145 | 163 | } |
|
146 | 164 | //![3] |
|
147 | 165 | |
|
148 | VPieModelMapper { | |
|
149 | series: pieSeries | |
|
150 | model: customModel | |
|
151 | labelsColumn: 1 | |
|
152 | valuesColumn: 2 | |
|
153 | firstRow: 1 | |
|
154 | } | |
|
155 | ||
|
156 | 166 | Component.onCompleted: { |
|
157 | 167 | createDefaultAxes(); |
|
158 | 168 | setAxisX(categoryAxis,myBarSeries) |
|
159 | } | |
|
169 | setAxisX(categoryAxis,lineSeries1) | |
|
170 | setAxisX(categoryAxis,lineSeries2) | |
|
171 | setAxisX(categoryAxis,lineSeries3) | |
|
172 | setAxisX(categoryAxis,lineSeries4) | |
|
173 | setAxisX(categoryAxis,lineSeries5) | |
|
174 | setAxisY(yAxis,myBarSeries) | |
|
175 | setAxisY(yAxis,lineSeries1) | |
|
176 | setAxisY(yAxis,lineSeries2) | |
|
177 | setAxisY(yAxis,lineSeries3) | |
|
178 | setAxisY(yAxis,lineSeries4) | |
|
179 | setAxisY(yAxis,lineSeries5) | |
|
180 | categoryAxis.min = "2007" | |
|
181 | categoryAxis.max = "2014" | |
|
182 | } | |
|
160 | 183 | } |
|
161 | 184 | } |
General Comments 0
You need to be logged in to leave comments.
Login now