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