##// END OF EJS Templates
Tuning qml chart demo pie and area charts
Tero Ahola -
r1325:7f47f3c844a4
parent child
Show More
@@ -1,104 +1,56
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
24 24 Rectangle {
25 25 anchors.fill: parent
26 26 property int __explodedIndex: -1
27 27 property variant otherSlice: 0
28 28
29 29 ChartView {
30 30 id: chart
31 31 title: "Top-5 car brand shares in Finland"
32 anchors.top: parent.top
33 anchors.bottom: button.top
34 anchors.left: parent.left
35 anchors.right: parent.right
32 anchors.fill: parent
36 33 theme: ChartView.ChartThemeLight
37 34 legend: ChartView.LegendBottom
38 35 animationOptions: ChartView.SeriesAnimations
39 36
40 37 // If you have static data, you can simply use the PieSlice API
41 38 PieSeries {
42 39 id: pieSeries
43 PieSlice { id: volkswagenSlice; label: "Volkswagen"; value: 13.5 }
40 onClicked: {
41 slice.exploded = !slice.exploded;
42 }
43 PieSlice { label: "Volkswagen"; value: 13.5 }
44 44 PieSlice { label: "Toyota"; value: 10.9 }
45 45 PieSlice { label: "Ford"; value: 8.6 }
46 46 PieSlice { label: "Skoda"; value: 8.2 }
47 47 PieSlice { label: "Volvo"; value: 6.8 }
48 48 }
49 49 }
50 50
51 51 Component.onCompleted: {
52 volkswagenSlice.exploded = true;
53 52 // You can also add slices dynamically
54 53 otherSlice = pieSeries.append("Others", 52.0);
55 }
56
57 Timer {
58 repeat: true
59 interval: 2000
60 running: true
61 onTriggered: {
62 // Set all slices as not exploded
63 for (var i = 0; i < pieSeries.count; i++)
64 pieSeries.at(i).exploded = false;
65
66 // Explode one of the slices
67 __explodedIndex = (__explodedIndex + 1) % pieSeries.count;
68 pieSeries.at(__explodedIndex).exploded = true;
69
70 54 pieSeries.find("Volkswagen").exploded = true;
71 // TODO: implement for convenience
72 // pieSeries.removeAll("Ford");
73 }
74 }
75
76 Rectangle {
77 id: button
78 anchors.bottom: parent.bottom
79 anchors.bottomMargin: 10
80 anchors.horizontalCenter: parent.horizontalCenter
81 height: 40
82 width: 100
83 color: "orange"
84 radius: 5
85 Text {
86 id: buttonText
87 anchors.centerIn: parent
88 text: "Hide others"
89 }
90 MouseArea {
91 anchors.fill: parent
92 onClicked: {
93 if (buttonText.text == "Show others") {
94 buttonText.text = "Hide others";
95 // TODO: ?
96 otherSlice.visible = true;
97 } else {
98 buttonText.text = "Show others";
99 otherSlice.visible = false;
100 }
101 }
102 }
103 55 }
104 56 }
@@ -1,130 +1,143
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
24 24 Rectangle {
25 25 anchors.fill: parent
26 26
27 27 ChartView {
28 28 title: "NHL All-Star Team Players"
29 29 anchors.fill: parent
30 30 theme: ChartView.ChartThemeHighContrast
31 31 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
32 32 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
33 33
34 34 AreaSeries {
35 35 name: "Russian"
36 36 upperSeries: LineSeries {
37 37 XyPoint { x: 0; y: 1 }
38 38 XyPoint { x: 1; y: 1 }
39 39 XyPoint { x: 2; y: 1 }
40 40 XyPoint { x: 3; y: 1 }
41 41 XyPoint { x: 4; y: 1 }
42 42 XyPoint { x: 5; y: 0 }
43 43 XyPoint { x: 6; y: 1 }
44 44 XyPoint { x: 7; y: 1 }
45 45 XyPoint { x: 8; y: 4 }
46 46 XyPoint { x: 9; y: 3 }
47 47 XyPoint { x: 10; y: 2 }
48 48 XyPoint { x: 11; y: 1 }
49 49 }
50 50 lowerSeries: LineSeries {
51 51 XyPoint { x: 0; y: 0 }
52 52 XyPoint { x: 1; y: 0 }
53 53 XyPoint { x: 2; y: 0 }
54 54 XyPoint { x: 3; y: 0 }
55 55 XyPoint { x: 4; y: 0 }
56 56 XyPoint { x: 5; y: 0 }
57 57 XyPoint { x: 6; y: 0 }
58 58 XyPoint { x: 7; y: 0 }
59 59 XyPoint { x: 8; y: 0 }
60 60 XyPoint { x: 9; y: 0 }
61 61 XyPoint { x: 10; y: 0 }
62 62 XyPoint { x: 11; y: 0 }
63 63 }
64 onClicked: {
65 color = "red";
66 borderColor = "black";
67 }
64 68 }
65 69
66 70 AreaSeries {
71 id: swedish
67 72 name: "Swedish"
68 73 upperSeries: LineSeries {
69 74 XyPoint { x: 0; y: 1 }
70 75 XyPoint { x: 1; y: 1 }
71 76 XyPoint { x: 2; y: 3 }
72 77 XyPoint { x: 3; y: 3 }
73 78 XyPoint { x: 4; y: 2 }
74 79 XyPoint { x: 5; y: 0 }
75 80 XyPoint { x: 6; y: 2 }
76 81 XyPoint { x: 7; y: 1 }
77 82 XyPoint { x: 8; y: 2 }
78 83 XyPoint { x: 9; y: 1 }
79 84 XyPoint { x: 10; y: 3 }
80 85 XyPoint { x: 11; y: 3 }
81 86 }
82 87 lowerSeries: LineSeries {
83 88 XyPoint { x: 0; y: 0 }
84 89 XyPoint { x: 1; y: 0 }
85 90 XyPoint { x: 2; y: 0 }
86 91 XyPoint { x: 3; y: 0 }
87 92 XyPoint { x: 4; y: 0 }
88 93 XyPoint { x: 5; y: 0 }
89 94 XyPoint { x: 6; y: 0 }
90 95 XyPoint { x: 7; y: 0 }
91 96 XyPoint { x: 8; y: 0 }
92 97 XyPoint { x: 9; y: 0 }
93 98 XyPoint { x: 10; y: 0 }
94 99 XyPoint { x: 11; y: 0 }
95 100 }
101 onClicked: {
102 color = "yellow";
103 borderColor = "blue";
104 }
96 105 }
97 106
98 107 AreaSeries {
99 108 name: "Finnish"
100 109 upperSeries: LineSeries {
101 110 XyPoint { x: 0; y: 0 }
102 111 XyPoint { x: 1; y: 0 }
103 112 XyPoint { x: 2; y: 0 }
104 113 XyPoint { x: 3; y: 0 }
105 114 XyPoint { x: 4; y: 0 }
106 115 XyPoint { x: 5; y: 0 }
107 116 XyPoint { x: 6; y: 1 }
108 117 XyPoint { x: 7; y: 0 }
109 118 XyPoint { x: 8; y: 0 }
110 119 XyPoint { x: 9; y: 0 }
111 120 XyPoint { x: 10; y: 0 }
112 121 XyPoint { x: 11; y: 1 }
113 122 }
114 123 lowerSeries: LineSeries {
115 124 XyPoint { x: 0; y: 0 }
116 125 XyPoint { x: 1; y: 0 }
117 126 XyPoint { x: 2; y: 0 }
118 127 XyPoint { x: 3; y: 0 }
119 128 XyPoint { x: 4; y: 0 }
120 129 XyPoint { x: 5; y: 0 }
121 130 XyPoint { x: 6; y: 0 }
122 131 XyPoint { x: 7; y: 0 }
123 132 XyPoint { x: 8; y: 0 }
124 133 XyPoint { x: 9; y: 0 }
125 134 XyPoint { x: 10; y: 0 }
126 135 XyPoint { x: 11; y: 0 }
127 136 }
137 onClicked: {
138 color = "white";
139 borderColor = "blue";
140 }
128 141 }
129 142 }
130 143 }
@@ -1,41 +1,86
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
24 24 Rectangle {
25 25 width: parent.width
26 26 height: parent.height
27 property int __viewNumber: 0
27 property int viewNumber: 1
28 28
29 Loader {
30 id: loader
31 anchors.top: parent.top
32 anchors.bottom: buttons.top
33 anchors.left: parent.left
34 anchors.right: parent.right
35 source: "View" + viewNumber + ".qml";
36 }
37
38 Row {
39 id: buttons
40 anchors.bottom: parent.bottom
41 anchors.bottomMargin: 5
42 anchors.horizontalCenter: parent.horizontalCenter
43 spacing: 10
44
45 Rectangle {
46 height: 35
47 width: 55
48 color: "grey"
49 radius: 5
50 Text {
51 anchors.centerIn: parent
52 text: "previous"
53 }
29 54 MouseArea {
30 55 anchors.fill: parent
31 56 onClicked: {
32 __viewNumber++;
57 var i = viewNumber - 1;
58 if (i <= 0)
59 viewNumber = 5;
60 else
61 viewNumber = i;
33 62 }
34 63 }
35
36 Loader {
37 id: loader
64 }
65 Rectangle {
66 height: 35
67 width: 55
68 color: "grey"
69 radius: 5
70 Text {
71 anchors.centerIn: parent
72 text: "next"
73 }
74 MouseArea {
38 75 anchors.fill: parent
39 source: "View" + (__viewNumber % 5 + 1) + ".qml";
76 onClicked: {
77 var i = viewNumber + 1;
78 if (i > 5)
79 viewNumber = 1;
80 else
81 viewNumber = i;
82 }
83 }
84 }
40 85 }
41 86 }
@@ -1,100 +1,101
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 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 22 #include <QtDeclarative/qdeclarative.h>
23 23 #include "qchart.h"
24 24 #include "qaxiscategories.h"
25 25 #include "declarativechart.h"
26 26 #include "declarativexypoint.h"
27 27 #include "declarativelineseries.h"
28 28 #include "declarativesplineseries.h"
29 29 #include "declarativeareaseries.h"
30 30 #include "declarativescatterseries.h"
31 31 #include "declarativebarseries.h"
32 32 #include "declarativepieseries.h"
33 33 #include <QVXYModelMapper>
34 34 #include <QHXYModelMapper>
35 35 #include <QHPieModelMapper>
36 36 #include <QVPieModelMapper>
37 37 #include <QHBarModelMapper>
38 38 #include <QVBarModelMapper>
39 39
40 40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 41
42 42 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 virtual void registerTypes(const char *uri)
47 47 {
48 48 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
49 49
50 50 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
51 51 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
52 52 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
53 53 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
54 54 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
55 55 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
56 56 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
57 57 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
58 58 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
59 59 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
60 60 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
61 61 qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice");
62 62 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
63 63 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
64 64 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
65 65 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
66 66 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
67 67 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
68 68 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
69 69
70
71 70 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
72 71 QLatin1String("Trying to create uncreatable: QScatterSeries."));
73 72 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
74 73 QLatin1String("Trying to create uncreatable: QPieSeries."));
74 qmlRegisterUncreatableType<QPieSlice>(uri, 1, 0, "QPieSlice",
75 QLatin1String("Trying to create uncreatable: QPieSlice."));
75 76 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
76 77 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
77 78 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
78 79 QLatin1String("Trying to create uncreatable: XYModelMapper."));
79 80 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
80 81 QLatin1String("Trying to create uncreatable: PieModelMapper."));
81 82 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
82 83 QLatin1String("Trying to create uncreatable: BarModelMapper."));
83 84 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
84 85 QLatin1String("Trying to create uncreatable: AbstractSeries."));
85 86 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
86 87 QLatin1String("Trying to create uncreatable: Axis."));
87 88 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
88 89 QLatin1String("Trying to create uncreatable: PieModelMapper."));
89 90 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
90 91 QLatin1String("Trying to create uncreatable: XYModelMapper."));
91 92 }
92 93 };
93 94
94 95 #include "plugin.moc"
95 96
96 97 QTCOMMERCIALCHART_END_NAMESPACE
97 98
98 99 QTCOMMERCIALCHART_USE_NAMESPACE
99 100
100 101 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
General Comments 0
You need to be logged in to leave comments. Login now