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