##// END OF EJS Templates
Tuning qml chart demo pie and area charts
Tero Ahola -
r1325:7f47f3c844a4
parent child
Show More
@@ -29,10 +29,7 Rectangle {
29 ChartView {
29 ChartView {
30 id: chart
30 id: chart
31 title: "Top-5 car brand shares in Finland"
31 title: "Top-5 car brand shares in Finland"
32 anchors.top: parent.top
32 anchors.fill: parent
33 anchors.bottom: button.top
34 anchors.left: parent.left
35 anchors.right: parent.right
36 theme: ChartView.ChartThemeLight
33 theme: ChartView.ChartThemeLight
37 legend: ChartView.LegendBottom
34 legend: ChartView.LegendBottom
38 animationOptions: ChartView.SeriesAnimations
35 animationOptions: ChartView.SeriesAnimations
@@ -40,7 +37,10 Rectangle {
40 // If you have static data, you can simply use the PieSlice API
37 // If you have static data, you can simply use the PieSlice API
41 PieSeries {
38 PieSeries {
42 id: pieSeries
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 PieSlice { label: "Toyota"; value: 10.9 }
44 PieSlice { label: "Toyota"; value: 10.9 }
45 PieSlice { label: "Ford"; value: 8.6 }
45 PieSlice { label: "Ford"; value: 8.6 }
46 PieSlice { label: "Skoda"; value: 8.2 }
46 PieSlice { label: "Skoda"; value: 8.2 }
@@ -49,56 +49,8 Rectangle {
49 }
49 }
50
50
51 Component.onCompleted: {
51 Component.onCompleted: {
52 volkswagenSlice.exploded = true;
53 // You can also add slices dynamically
52 // You can also add slices dynamically
54 otherSlice = pieSeries.append("Others", 52.0);
53 otherSlice = pieSeries.append("Others", 52.0);
55 }
54 pieSeries.find("Volkswagen").exploded = true;
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 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 }
@@ -61,9 +61,14 Rectangle {
61 XyPoint { x: 10; y: 0 }
61 XyPoint { x: 10; y: 0 }
62 XyPoint { x: 11; y: 0 }
62 XyPoint { x: 11; y: 0 }
63 }
63 }
64 onClicked: {
65 color = "red";
66 borderColor = "black";
67 }
64 }
68 }
65
69
66 AreaSeries {
70 AreaSeries {
71 id: swedish
67 name: "Swedish"
72 name: "Swedish"
68 upperSeries: LineSeries {
73 upperSeries: LineSeries {
69 XyPoint { x: 0; y: 1 }
74 XyPoint { x: 0; y: 1 }
@@ -93,6 +98,10 Rectangle {
93 XyPoint { x: 10; y: 0 }
98 XyPoint { x: 10; y: 0 }
94 XyPoint { x: 11; y: 0 }
99 XyPoint { x: 11; y: 0 }
95 }
100 }
101 onClicked: {
102 color = "yellow";
103 borderColor = "blue";
104 }
96 }
105 }
97
106
98 AreaSeries {
107 AreaSeries {
@@ -125,6 +134,10 Rectangle {
125 XyPoint { x: 10; y: 0 }
134 XyPoint { x: 10; y: 0 }
126 XyPoint { x: 11; y: 0 }
135 XyPoint { x: 11; y: 0 }
127 }
136 }
137 onClicked: {
138 color = "white";
139 borderColor = "blue";
140 }
128 }
141 }
129 }
142 }
130 }
143 }
@@ -24,18 +24,63 import QtCommercial.Chart 1.0
24 Rectangle {
24 Rectangle {
25 width: parent.width
25 width: parent.width
26 height: parent.height
26 height: parent.height
27 property int __viewNumber: 0
27 property int viewNumber: 1
28
29 MouseArea {
30 anchors.fill: parent
31 onClicked: {
32 __viewNumber++;
33 }
34 }
35
28
36 Loader {
29 Loader {
37 id: loader
30 id: loader
38 anchors.fill: parent
31 anchors.top: parent.top
39 source: "View" + (__viewNumber % 5 + 1) + ".qml";
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 }
54 MouseArea {
55 anchors.fill: parent
56 onClicked: {
57 var i = viewNumber - 1;
58 if (i <= 0)
59 viewNumber = 5;
60 else
61 viewNumber = i;
62 }
63 }
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 {
75 anchors.fill: parent
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 }
@@ -67,11 +67,12 public:
67 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
67 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
68 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
68 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
69
69
70
71 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
70 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
72 QLatin1String("Trying to create uncreatable: QScatterSeries."));
71 QLatin1String("Trying to create uncreatable: QScatterSeries."));
73 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
72 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
74 QLatin1String("Trying to create uncreatable: QPieSeries."));
73 QLatin1String("Trying to create uncreatable: QPieSeries."));
74 qmlRegisterUncreatableType<QPieSlice>(uri, 1, 0, "QPieSlice",
75 QLatin1String("Trying to create uncreatable: QPieSlice."));
75 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
76 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
76 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
77 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
77 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
78 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
General Comments 0
You need to be logged in to leave comments. Login now