##// END OF EJS Templates
Named all series in example applications
Tero Ahola -
r1226:bae2376cbfec
parent child
Show More
@@ -1,159 +1,159
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.1
21 import QtQuick 1.1
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 width: 360
25 width: 360
26 height: 360
26 height: 360
27
27
28 //![1]
28 //![1]
29 ChartView {
29 ChartView {
30 id: chartView
30 id: chartView
31 title: "Weather forecast"
31 title: "Weather forecast"
32 //![1]
32 //![1]
33 anchors.top: parent.top
33 anchors.top: parent.top
34 anchors.bottom: weatherImageRow.top
34 anchors.bottom: weatherImageRow.top
35 anchors.left: parent.left
35 anchors.left: parent.left
36 anchors.right: parent.right
36 anchors.right: parent.right
37 legend: ChartView.LegendTop
37 legend: ChartView.LegendTop
38
38
39 //![2]
39 //![2]
40 // BarSeries {
40 // BarSeries {
41 GroupedBarSeries {
41 GroupedBarSeries {
42 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
42 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
43 BarSet {
43 BarSet {
44 id: rainfallSet
44 id: rainfallSet
45 name: "Rainfall"
45 name: "Rainfall"
46 }
46 }
47 }
47 }
48
48
49 ScatterSeries {
49 ScatterSeries {
50 id: maxTempSeries
50 id: maxTempSeries
51 name: "Max. temperature"
51 name: "Max. temperature"
52 }
52 }
53
53
54 ScatterSeries {
54 ScatterSeries {
55 id: minTempSeries
55 id: minTempSeries
56 name: "Min. temperature"
56 name: "Min. temperature"
57 }
57 }
58 //![2]
58 //![2]
59 }
59 }
60
60
61 // A timer to refresh the forecast every 5 minutes
61 // A timer to refresh the forecast every 5 minutes
62 Timer {
62 Timer {
63 interval: 300000;
63 interval: 300000
64 repeat: true
64 repeat: true
65 triggeredOnStart: true
65 triggeredOnStart: true
66 running: true
66 running: true
67 onTriggered: {
67 onTriggered: {
68 if (weatherAppKey != "") {
68 if (weatherAppKey != "") {
69 //![3]
69 //![3]
70 // Make HTTP GET request and parse the result
70 // Make HTTP GET request and parse the result
71 var xhr = new XMLHttpRequest;
71 var xhr = new XMLHttpRequest;
72 xhr.open("GET",
72 xhr.open("GET",
73 "http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key="
73 "http://free.worldweatheronline.com/feed/weather.ashx?q=Jyv%c3%a4skyl%c3%a4,Finland&format=json&num_of_days=5&key="
74 + weatherAppKey);
74 + weatherAppKey);
75 xhr.onreadystatechange = function() {
75 xhr.onreadystatechange = function() {
76 if (xhr.readyState == XMLHttpRequest.DONE) {
76 if (xhr.readyState == XMLHttpRequest.DONE) {
77 var a = JSON.parse(xhr.responseText);
77 var a = JSON.parse(xhr.responseText);
78 parseWeatherData(a);
78 parseWeatherData(a);
79 }
79 }
80 }
80 }
81 xhr.send();
81 xhr.send();
82 //![3]
82 //![3]
83 } else {
83 } else {
84 // No app key for worldweatheronline.com given by the user -> use static data
84 // No app key for worldweatheronline.com given by the user -> use static data
85 var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}";
85 var responseText = "{ \"data\": { \"current_condition\": [ {\"cloudcover\": \"10\", \"humidity\": \"61\", \"observation_time\": \"06:26 AM\", \"precipMM\": \"0.0\", \"pressure\": \"1022\", \"temp_C\": \"6\", \"temp_F\": \"43\", \"visibility\": \"10\", \"weatherCode\": \"113\", \"weatherDesc\": [ {\"value\": \"Sunny\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0001_sunny.png\" } ], \"winddir16Point\": \"SE\", \"winddirDegree\": \"140\", \"windspeedKmph\": \"7\", \"windspeedMiles\": \"4\" } ], \"request\": [ {\"query\": \"Jyvaskyla, Finland\", \"type\": \"City\" } ], \"weather\": [ {\"date\": \"2012-05-09\", \"precipMM\": \"0.4\", \"tempMaxC\": \"14\", \"tempMaxF\": \"57\", \"tempMinC\": \"7\", \"tempMinF\": \"45\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"S\", \"winddirDegree\": \"179\", \"winddirection\": \"S\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-10\", \"precipMM\": \"2.4\", \"tempMaxC\": \"13\", \"tempMaxF\": \"55\", \"tempMinC\": \"8\", \"tempMinF\": \"46\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SW\", \"winddirDegree\": \"219\", \"winddirection\": \"SW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" }, {\"date\": \"2012-05-11\", \"precipMM\": \"11.1\", \"tempMaxC\": \"15\", \"tempMaxF\": \"59\", \"tempMinC\": \"7\", \"tempMinF\": \"44\", \"weatherCode\": \"266\", \"weatherDesc\": [ {\"value\": \"Light drizzle\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png\" } ], \"winddir16Point\": \"SSW\", \"winddirDegree\": \"200\", \"winddirection\": \"SSW\", \"windspeedKmph\": \"20\", \"windspeedMiles\": \"12\" }, {\"date\": \"2012-05-12\", \"precipMM\": \"2.8\", \"tempMaxC\": \"7\", \"tempMaxF\": \"44\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"317\", \"weatherDesc\": [ {\"value\": \"Light sleet\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0021_cloudy_with_sleet.png\" } ], \"winddir16Point\": \"NW\", \"winddirDegree\": \"311\", \"winddirection\": \"NW\", \"windspeedKmph\": \"24\", \"windspeedMiles\": \"15\" }, {\"date\": \"2012-05-13\", \"precipMM\": \"0.4\", \"tempMaxC\": \"6\", \"tempMaxF\": \"42\", \"tempMinC\": \"2\", \"tempMinF\": \"35\", \"weatherCode\": \"116\", \"weatherDesc\": [ {\"value\": \"Partly Cloudy\" } ], \"weatherIconUrl\": [ {\"value\": \"http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0002_sunny_intervals.png\" } ], \"winddir16Point\": \"WNW\", \"winddirDegree\": \"281\", \"winddirection\": \"WNW\", \"windspeedKmph\": \"21\", \"windspeedMiles\": \"13\" } ] }}";
86 var a = JSON.parse(responseText);
86 var a = JSON.parse(responseText);
87 parseWeatherData(a);
87 parseWeatherData(a);
88 }
88 }
89 }
89 }
90 }
90 }
91
91
92 Row {
92 Row {
93 id: weatherImageRow
93 id: weatherImageRow
94 anchors.bottom: parent.bottom
94 anchors.bottom: parent.bottom
95 anchors.bottomMargin: 10
95 anchors.bottomMargin: 10
96 anchors.left: parent.left
96 anchors.left: parent.left
97 anchors.leftMargin: 25
97 anchors.leftMargin: 25
98 anchors.right: parent.right
98 anchors.right: parent.right
99 anchors.rightMargin: 25
99 anchors.rightMargin: 25
100
100
101 ListModel {
101 ListModel {
102 id: weatherImageModel
102 id: weatherImageModel
103 }
103 }
104
104
105 Repeater {
105 Repeater {
106 id: repeater
106 id: repeater
107 model: weatherImageModel
107 model: weatherImageModel
108 delegate: Image {
108 delegate: Image {
109 source: imageSource
109 source: imageSource
110 width: weatherImageRow.width / weatherImageModel.count
110 width: weatherImageRow.width / weatherImageModel.count
111 height: width
111 height: width
112 fillMode: Image.PreserveAspectCrop
112 fillMode: Image.PreserveAspectCrop
113 }
113 }
114 }
114 }
115 }
115 }
116
116
117 function parseWeatherData(weatherData) {
117 function parseWeatherData(weatherData) {
118 // Clear previous values
118 // Clear previous values
119 chartView.axisX.min = 0;
119 chartView.axisX.min = 0;
120 chartView.axisX.max = 5;
120 chartView.axisX.max = 5;
121 chartView.axisY.min = 0;
121 chartView.axisY.min = 0;
122 chartView.axisY.max = 5;
122 chartView.axisY.max = 5;
123 maxTempSeries.clear();
123 maxTempSeries.clear();
124 minTempSeries.clear();
124 minTempSeries.clear();
125 weatherImageModel.clear();
125 weatherImageModel.clear();
126
126
127 //![4]
127 //![4]
128 // Loop through the parsed JSON
128 // Loop through the parsed JSON
129 for (var i in weatherData.data.weather) {
129 for (var i in weatherData.data.weather) {
130 var weatherObj = weatherData.data.weather[i];
130 var weatherObj = weatherData.data.weather[i];
131 //![4]
131 //![4]
132
132
133 //![5]
133 //![5]
134 // Store temperature values, rainfall and weather icon
134 // Store temperature values, rainfall and weather icon
135 maxTempSeries.append(i, weatherObj.tempMaxC);
135 maxTempSeries.append(i, weatherObj.tempMaxC);
136 minTempSeries.append(i, weatherObj.tempMinC);
136 minTempSeries.append(i, weatherObj.tempMinC);
137 rainfallSet.append(i, weatherObj.precipMM);
137 rainfallSet.append(i, weatherObj.precipMM);
138
138
139 weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});
139 weatherImageModel.append({"imageSource":weatherObj.weatherIconUrl[0].value});
140 //![5]
140 //![5]
141
141
142 // Update scale of the chart
142 // Update scale of the chart
143 chartView.axisX.min = 0;
143 chartView.axisX.min = 0;
144 chartView.axisX.max = i;
144 chartView.axisX.max = i;
145 while (chartView.axisY.min >= Number(weatherObj.tempMinC))
145 while (chartView.axisY.min >= Number(weatherObj.tempMinC))
146 chartView.axisY.min = chartView.axisY.min - 10;
146 chartView.axisY.min = chartView.axisY.min - 10;
147 while (chartView.axisY.max <= Number(weatherObj.tempMaxC))
147 while (chartView.axisY.max <= Number(weatherObj.tempMaxC))
148 chartView.axisY.max = chartView.axisY.max + 10;
148 chartView.axisY.max = chartView.axisY.max + 10;
149
149
150 // Set the x-axis labels to the dates of the forecast
150 // Set the x-axis labels to the dates of the forecast
151 // TODO: the API could probably be more intuitive..
151 // TODO: the API could probably be more intuitive..
152 // Now it takes an array of strings: chartView.axisXLabels = ["value1", "label1", "value2", "label2", ...]
152 // Now it takes an array of strings: chartView.axisXLabels = ["value1", "label1", "value2", "label2", ...]
153 var xLabels = chartView.axisXLabels;
153 var xLabels = chartView.axisXLabels;
154 xLabels[Number(i) * 2] = i;
154 xLabels[Number(i) * 2] = i;
155 xLabels[(Number(i) * 2) + 1] = weatherObj.date.substring(5, 10);
155 xLabels[(Number(i) * 2) + 1] = weatherObj.date.substring(5, 10);
156 chartView.axisXLabels = xLabels;
156 chartView.axisXLabels = xLabels;
157 }
157 }
158 }
158 }
159 }
159 }
@@ -1,79 +1,80
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 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QLineSeries>
24 #include <QLineSeries>
25 #include <QAreaSeries>
25 #include <QAreaSeries>
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
30 {
30 {
31 QApplication a(argc, argv);
31 QApplication a(argc, argv);
32
32
33 //![1]
33 //![1]
34 QLineSeries* series0 = new QLineSeries();
34 QLineSeries* series0 = new QLineSeries();
35 QLineSeries* series1 = new QLineSeries();
35 QLineSeries* series1 = new QLineSeries();
36 //![1]
36 //![1]
37
37
38 //![2]
38 //![2]
39 *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6)
39 *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6)
40 << QPointF(16, 7) << QPointF(18, 5);
40 << QPointF(16, 7) << QPointF(18, 5);
41 *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3)
41 *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3)
42 << QPointF(16, 4) << QPointF(18, 3);
42 << QPointF(16, 4) << QPointF(18, 3);
43 //![2]
43 //![2]
44
44
45 //![3]
45 //![3]
46 QAreaSeries* series = new QAreaSeries(series0, series1);
46 QAreaSeries* series = new QAreaSeries(series0, series1);
47 series->setName("Batman");
47 QPen pen(0x059605);
48 QPen pen(0x059605);
48 pen.setWidth(3);
49 pen.setWidth(3);
49 series->setPen(pen);
50 series->setPen(pen);
50
51
51 QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
52 QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
52 gradient.setColorAt(0.0, 0x3cc63c);
53 gradient.setColorAt(0.0, 0x3cc63c);
53 gradient.setColorAt(1.0, 0x26f626);
54 gradient.setColorAt(1.0, 0x26f626);
54 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
55 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
55 series->setBrush(gradient);
56 series->setBrush(gradient);
56 //![3]
57 //![3]
57
58
58 //![4]
59 //![4]
59 QChart* chart = new QChart();
60 QChart* chart = new QChart();
60 chart->addSeries(series);
61 chart->addSeries(series);
61 chart->setTitle("Simple areachart example");
62 chart->setTitle("Simple areachart example");
62 chart->axisX()->setRange(0, 20);
63 chart->axisX()->setRange(0, 20);
63 chart->axisY()->setRange(0, 10);
64 chart->axisY()->setRange(0, 10);
64 //![4]
65 //![4]
65
66
66 //![5]
67 //![5]
67 QChartView* chartView = new QChartView(chart);
68 QChartView* chartView = new QChartView(chart);
68 chartView->setRenderHint(QPainter::Antialiasing);
69 chartView->setRenderHint(QPainter::Antialiasing);
69 //![5]
70 //![5]
70
71
71 //![6]
72 //![6]
72 QMainWindow window;
73 QMainWindow window;
73 window.setCentralWidget(chartView);
74 window.setCentralWidget(chartView);
74 window.resize(400, 300);
75 window.resize(400, 300);
75 window.show();
76 window.show();
76 //![6]
77 //![6]
77
78
78 return a.exec();
79 return a.exec();
79 }
80 }
@@ -1,121 +1,122
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 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QLineSeries>
24 #include <QLineSeries>
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
27
28 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
29 {
29 {
30 QApplication a(argc, argv);
30 QApplication a(argc, argv);
31
31
32 //![1]
32 //![1]
33 QLineSeries* series = new QLineSeries();
33 QLineSeries* series = new QLineSeries();
34 series->setName("line");
34 *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5);
35 *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5);
35 QChart* chart = new QChart();
36 QChart* chart = new QChart();
36 chart->addSeries(series);
37 chart->addSeries(series);
37 //![1]
38 //![1]
38
39
39 //![2]
40 //![2]
40 // Customize series
41 // Customize series
41 QPen pen(QRgb(0xfdb157));
42 QPen pen(QRgb(0xfdb157));
42 pen.setWidth(5);
43 pen.setWidth(5);
43 series->setPen(pen);
44 series->setPen(pen);
44
45
45 // Customize chart title
46 // Customize chart title
46 QFont font;
47 QFont font;
47 font.setPixelSize(18);
48 font.setPixelSize(18);
48 chart->setTitleFont(font);
49 chart->setTitleFont(font);
49 chart->setTitleBrush(QBrush(Qt::white));
50 chart->setTitleBrush(QBrush(Qt::white));
50 chart->setTitle("Customchart example");
51 chart->setTitle("Customchart example");
51
52
52 // Customize chart background
53 // Customize chart background
53 QLinearGradient backgroundGradient;
54 QLinearGradient backgroundGradient;
54 backgroundGradient.setStart(QPointF(0,0));
55 backgroundGradient.setStart(QPointF(0,0));
55 backgroundGradient.setFinalStop(QPointF(0,1));
56 backgroundGradient.setFinalStop(QPointF(0,1));
56 backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
57 backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1));
57 backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
58 backgroundGradient.setColorAt(1.0, QRgb(0x4c4547));
58 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
59 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
59 chart->setBackgroundBrush(backgroundGradient);
60 chart->setBackgroundBrush(backgroundGradient);
60 //![2]
61 //![2]
61
62
62 //![3]
63 //![3]
63 QAxis* axisX = chart->axisX();
64 QAxis* axisX = chart->axisX();
64 QAxis* axisY = chart->axisY();
65 QAxis* axisY = chart->axisY();
65
66
66 // Customize axis label font
67 // Customize axis label font
67 QFont labelsFont;
68 QFont labelsFont;
68 labelsFont.setPixelSize(12);
69 labelsFont.setPixelSize(12);
69 axisX->setLabelsFont(labelsFont);
70 axisX->setLabelsFont(labelsFont);
70 axisY->setLabelsFont(labelsFont);
71 axisY->setLabelsFont(labelsFont);
71
72
72 // Customize axis colors
73 // Customize axis colors
73 QPen axisPen(QRgb(0xd18952));
74 QPen axisPen(QRgb(0xd18952));
74 axisPen.setWidth(2);
75 axisPen.setWidth(2);
75 axisX->setAxisPen(axisPen);
76 axisX->setAxisPen(axisPen);
76 axisY->setAxisPen(axisPen);
77 axisY->setAxisPen(axisPen);
77
78
78 // Customize axis label colors
79 // Customize axis label colors
79 QBrush axisBrush(Qt::white);
80 QBrush axisBrush(Qt::white);
80 axisX->setLabelsBrush(axisBrush);
81 axisX->setLabelsBrush(axisBrush);
81 axisY->setLabelsBrush(axisBrush);
82 axisY->setLabelsBrush(axisBrush);
82
83
83 // Customize grid lines and shades
84 // Customize grid lines and shades
84 axisX->setGridLineVisible(false);
85 axisX->setGridLineVisible(false);
85 axisY->setGridLineVisible(false);
86 axisY->setGridLineVisible(false);
86 axisY->setShadesPen(Qt::NoPen);
87 axisY->setShadesPen(Qt::NoPen);
87 axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3)));
88 axisY->setShadesBrush(QBrush(QRgb(0xa5a2a3)));
88 axisY->setShadesVisible(true);
89 axisY->setShadesVisible(true);
89 //![3]
90 //![3]
90
91
91 //![4]
92 //![4]
92 QAxisCategories* categoriesX = chart->axisX()->categories();
93 QAxisCategories* categoriesX = chart->axisX()->categories();
93 categoriesX->insert(1,"low");
94 categoriesX->insert(1,"low");
94 categoriesX->insert(5,"optimal");
95 categoriesX->insert(5,"optimal");
95 categoriesX->insert(10,"high");
96 categoriesX->insert(10,"high");
96
97
97 QAxisCategories* categoriesY = chart->axisY()->categories();
98 QAxisCategories* categoriesY = chart->axisY()->categories();
98 categoriesY->insert(1,"slow");
99 categoriesY->insert(1,"slow");
99 categoriesY->insert(5,"med");
100 categoriesY->insert(5,"med");
100 categoriesY->insert(10,"fast");
101 categoriesY->insert(10,"fast");
101
102
102 axisX->setRange(0,10);
103 axisX->setRange(0,10);
103 axisX->setTicksCount(4);
104 axisX->setTicksCount(4);
104 axisY->setRange(0,10);
105 axisY->setRange(0,10);
105 axisY->setTicksCount(4);
106 axisY->setTicksCount(4);
106 //![4]
107 //![4]
107
108
108 //![5]
109 //![5]
109 QChartView* chartView = new QChartView(chart);
110 QChartView* chartView = new QChartView(chart);
110 chartView->setRenderHint(QPainter::Antialiasing);
111 chartView->setRenderHint(QPainter::Antialiasing);
111 //![5]
112 //![5]
112
113
113 //![6]
114 //![6]
114 QMainWindow window;
115 QMainWindow window;
115 window.setCentralWidget(chartView);
116 window.setCentralWidget(chartView);
116 window.resize(400, 300);
117 window.resize(400, 300);
117 window.show();
118 window.show();
118 //![6]
119 //![6]
119
120
120 return a.exec();
121 return a.exec();
121 }
122 }
@@ -1,64 +1,65
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 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QLineSeries>
24 #include <QLineSeries>
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
27
28 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
29 {
29 {
30 QApplication a(argc, argv);
30 QApplication a(argc, argv);
31
31
32 //![1]
32 //![1]
33 QLineSeries* series = new QLineSeries();
33 QLineSeries* series = new QLineSeries();
34 series->setName("line");
34 //![1]
35 //![1]
35
36
36 //![2]
37 //![2]
37 series->append(0, 6);
38 series->append(0, 6);
38 series->append(2, 4);
39 series->append(2, 4);
39 series->append(3, 8);
40 series->append(3, 8);
40 series->append(7, 4);
41 series->append(7, 4);
41 series->append(10, 5);
42 series->append(10, 5);
42 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
43 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
43 //![2]
44 //![2]
44
45
45 //![3]
46 //![3]
46 QChart* chart = new QChart();
47 QChart* chart = new QChart();
47 chart->addSeries(series);
48 chart->addSeries(series);
48 chart->setTitle("Simple line chart example");
49 chart->setTitle("Simple line chart example");
49 //![3]
50 //![3]
50
51
51 //![4]
52 //![4]
52 QChartView* chartView = new QChartView(chart);
53 QChartView* chartView = new QChartView(chart);
53 chartView->setRenderHint(QPainter::Antialiasing);
54 chartView->setRenderHint(QPainter::Antialiasing);
54 //![4]
55 //![4]
55
56
56 //![5]
57 //![5]
57 QMainWindow window;
58 QMainWindow window;
58 window.setCentralWidget(chartView);
59 window.setCentralWidget(chartView);
59 window.resize(400, 300);
60 window.resize(400, 300);
60 window.show();
61 window.show();
61 //![5]
62 //![5]
62
63
63 return a.exec();
64 return a.exec();
64 }
65 }
@@ -1,111 +1,113
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 #include "tablewidget.h"
21 #include "tablewidget.h"
22 #include "customtablemodel.h"
22 #include "customtablemodel.h"
23 #include <QGridLayout>
23 #include <QGridLayout>
24 #include <QTableView>
24 #include <QTableView>
25 #include <QChart>
25 #include <QChart>
26 #include <QChartView>
26 #include <QChartView>
27 #include <QLineSeries>
27 #include <QLineSeries>
28 #include "qxymodelmapper.h"
28 #include "qxymodelmapper.h"
29 #include <QHeaderView>
29 #include <QHeaderView>
30
30
31 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
32
32
33 TableWidget::TableWidget(QWidget *parent)
33 TableWidget::TableWidget(QWidget *parent)
34 : QWidget(parent)
34 : QWidget(parent)
35 {
35 {
36 // create simple model for storing data
36 // create simple model for storing data
37 // user's table data model
37 // user's table data model
38 //! [1]
38 //! [1]
39 CustomTableModel *model = new CustomTableModel;
39 CustomTableModel *model = new CustomTableModel;
40 //! [1]
40 //! [1]
41
41
42 //! [2]
42 //! [2]
43 // create table view and add model to it
43 // create table view and add model to it
44 QTableView *tableView = new QTableView;
44 QTableView *tableView = new QTableView;
45 tableView->setModel(model);
45 tableView->setModel(model);
46 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
46 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
47 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
47 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
48 //! [2]
48 //! [2]
49
49
50 //! [3]
50 //! [3]
51 QChart *chart = new QChart;
51 QChart *chart = new QChart;
52 chart->setAnimationOptions(QChart::AllAnimations);
52 chart->setAnimationOptions(QChart::AllAnimations);
53 //! [3]
53 //! [3]
54
54
55 // series 1
55 // series 1
56 //! [4]
56 //! [4]
57 QLineSeries *series = new QLineSeries;
57 QLineSeries *series = new QLineSeries;
58 series->setName("line1");
58 series->setModel(model);
59 series->setModel(model);
59
60
60 QXYModelMapper *mapper = new QXYModelMapper;
61 QXYModelMapper *mapper = new QXYModelMapper;
61 mapper->setMapX(0);
62 mapper->setMapX(0);
62 mapper->setMapY(1);
63 mapper->setMapY(1);
63 series->setModelMapper(mapper);
64 series->setModelMapper(mapper);
64 // series->setModelMapping(0, 1, Qt::Vertical);
65 // series->setModelMapping(0, 1, Qt::Vertical);
65 chart->addSeries(series);
66 chart->addSeries(series);
66 //! [4]
67 //! [4]
67
68
68 //! [5]
69 //! [5]
69 // for storing color hex from the series
70 // for storing color hex from the series
70 QString seriesColorHex = "#000000";
71 QString seriesColorHex = "#000000";
71
72
72 // get the color of the series and use it for showing the mapped area
73 // get the color of the series and use it for showing the mapped area
73 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
74 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
74 model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
75 model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount()));
75 //! [5]
76 //! [5]
76
77
77 // series 2
78 // series 2
78 //! [6]
79 //! [6]
79 series = new QLineSeries;
80 series = new QLineSeries;
81 series->setName("line2");
80 series->setModel(model);
82 series->setModel(model);
81
83
82 mapper = new QXYModelMapper;
84 mapper = new QXYModelMapper;
83 mapper->setMapX(2);
85 mapper->setMapX(2);
84 mapper->setMapY(3);
86 mapper->setMapY(3);
85 series->setModelMapper(mapper);
87 series->setModelMapper(mapper);
86 // series->setModelMapping(2,3, Qt::Vertical);
88 // series->setModelMapping(2,3, Qt::Vertical);
87 chart->addSeries(series);
89 chart->addSeries(series);
88 //! [6]
90 //! [6]
89
91
90 //! [7]
92 //! [7]
91 // get the color of the series and use it for showing the mapped area
93 // get the color of the series and use it for showing the mapped area
92 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
94 seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper();
93 model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount()));
95 model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount()));
94 //! [7]
96 //! [7]
95
97
96 //! [8]
98 //! [8]
97 QChartView *chartView = new QChartView(chart);
99 QChartView *chartView = new QChartView(chart);
98 chartView->setRenderHint(QPainter::Antialiasing);
100 chartView->setRenderHint(QPainter::Antialiasing);
99 chartView->setMinimumSize(640, 480);
101 chartView->setMinimumSize(640, 480);
100 //! [8]
102 //! [8]
101
103
102 //! [9]
104 //! [9]
103 // create main layout
105 // create main layout
104 QGridLayout* mainLayout = new QGridLayout;
106 QGridLayout* mainLayout = new QGridLayout;
105 mainLayout->addWidget(tableView, 1, 0);
107 mainLayout->addWidget(tableView, 1, 0);
106 mainLayout->addWidget(chartView, 1, 1);
108 mainLayout->addWidget(chartView, 1, 1);
107 mainLayout->setColumnStretch(1, 1);
109 mainLayout->setColumnStretch(1, 1);
108 mainLayout->setColumnStretch(0, 0);
110 mainLayout->setColumnStretch(0, 0);
109 setLayout(mainLayout);
111 setLayout(mainLayout);
110 //! [9]
112 //! [9]
111 }
113 }
@@ -1,105 +1,109
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 #include "chartview.h"
21 #include "chartview.h"
22 #include <QLineSeries>
22 #include <QLineSeries>
23 #include <QScatterSeries>
23 #include <QScatterSeries>
24 #include <QSplineSeries>
24 #include <QSplineSeries>
25 #include <QAreaSeries>
25 #include <QAreaSeries>
26 #include <QTime>
26 #include <QTime>
27
27
28 ChartView::ChartView(QChart* chart,QWidget* parent):QChartView(chart,parent),
28 ChartView::ChartView(QChart* chart,QWidget* parent):QChartView(chart,parent),
29 m_index(-1),m_chart(chart)
29 m_index(-1),m_chart(chart)
30 {
30 {
31 m_chart->setTitle("Charts presenter");
31 m_chart->setTitle("Charts presenter");
32 m_chart->setBackgroundDropShadowEnabled(false);
32 m_chart->setBackgroundDropShadowEnabled(false);
33 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
33 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
34 m_timer.setInterval(3000);
34 m_timer.setInterval(3000);
35
35
36 //![1]
36 //![1]
37 QLineSeries* series0 = new QLineSeries();
37 QLineSeries* series0 = new QLineSeries();
38 series0->setName("line");
38 QPen blue(Qt::blue);
39 QPen blue(Qt::blue);
39 blue.setWidth(3);
40 blue.setWidth(3);
40 series0->setPen(blue);
41 series0->setPen(blue);
41
42
42 QScatterSeries* series1 = new QScatterSeries();
43 QScatterSeries* series1 = new QScatterSeries();
44 series1->setName("scatter");
43 QPen red(Qt::red);
45 QPen red(Qt::red);
44 red.setWidth(3);
46 red.setWidth(3);
45 series1->setPen(red);
47 series1->setPen(red);
46 series1->setBrush(Qt::white);
48 series1->setBrush(Qt::white);
47
49
48 QSplineSeries* series2 = new QSplineSeries();
50 QSplineSeries* series2 = new QSplineSeries();
51 series2->setName("spline");
49 QPen green(Qt::green);
52 QPen green(Qt::green);
50 green.setWidth(3);
53 green.setWidth(3);
51 series2->setPen(green);
54 series2->setPen(green);
52
55
53 QAreaSeries* series3 = new QAreaSeries(series0);
56 QAreaSeries* series3 = new QAreaSeries(series0);
57 series3->setName("area");
54 QPen yellow(Qt::black);
58 QPen yellow(Qt::black);
55 yellow.setWidth(3);
59 yellow.setWidth(3);
56 series3->setPen(yellow);
60 series3->setPen(yellow);
57 series3->setBrush(Qt::yellow);
61 series3->setBrush(Qt::yellow);
58 //![1]
62 //![1]
59
63
60 //![2]
64 //![2]
61 int numPoints = 10;
65 int numPoints = 10;
62
66
63 for (int x = 0; x <= numPoints; ++x) {
67 for (int x = 0; x <= numPoints; ++x) {
64 qreal y = qrand() % 100;
68 qreal y = qrand() % 100;
65 series0->append(x,y);
69 series0->append(x,y);
66 series1->append(x,y);
70 series1->append(x,y);
67 series2->append(x,y);
71 series2->append(x,y);
68 }
72 }
69 //![2]
73 //![2]
70
74
71 //![3]
75 //![3]
72 m_series<<series0;
76 m_series<<series0;
73 m_titles<< m_chart->title()+": LineChart";
77 m_titles<< m_chart->title()+": LineChart";
74 m_series<<series1;
78 m_series<<series1;
75 m_titles<< m_chart->title()+": ScatterChart";
79 m_titles<< m_chart->title()+": ScatterChart";
76 m_series<<series2;
80 m_series<<series2;
77 m_titles<< m_chart->title()+": SplineChart";
81 m_titles<< m_chart->title()+": SplineChart";
78 m_series<<series3;
82 m_series<<series3;
79 m_titles<< m_chart->title()+": AreaChart";
83 m_titles<< m_chart->title()+": AreaChart";
80 //![3]
84 //![3]
81
85
82 m_timer.start();
86 m_timer.start();
83 handleTimeout();
87 handleTimeout();
84 }
88 }
85
89
86 ChartView::~ChartView()
90 ChartView::~ChartView()
87 {
91 {
88 if(m_series.size()==0) return;
92 if(m_series.size()==0) return;
89 m_chart->removeSeries(m_series.at(m_index));
93 m_chart->removeSeries(m_series.at(m_index));
90 m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone
94 m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone
91 qDeleteAll(m_series);
95 qDeleteAll(m_series);
92 }
96 }
93
97
94 //![4]
98 //![4]
95 void ChartView::handleTimeout()
99 void ChartView::handleTimeout()
96 {
100 {
97 if(m_series.size()==0) return;
101 if(m_series.size()==0) return;
98 if(m_index>=0)
102 if(m_index>=0)
99 m_chart->removeSeries(m_series.at(m_index));
103 m_chart->removeSeries(m_series.at(m_index));
100 m_index++;
104 m_index++;
101 m_index=m_index%m_series.size();
105 m_index=m_index%m_series.size();
102 m_chart->addSeries(m_series.at(m_index));
106 m_chart->addSeries(m_series.at(m_index));
103 m_chart->setTitle(m_titles.at(m_index));
107 m_chart->setTitle(m_titles.at(m_index));
104 }
108 }
105 //![4]
109 //![4]
@@ -1,34 +1,36
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <QScatterSeries>
2 #include <QScatterSeries>
3
3
4 ChartView::ChartView(QWidget *parent) :
4 ChartView::ChartView(QWidget *parent) :
5 QChartView(new QChart(), parent)
5 QChartView(new QChart(), parent)
6 {
6 {
7 //![1]
7 //![1]
8 QScatterSeries *series0 = new QScatterSeries();
8 QScatterSeries *series0 = new QScatterSeries();
9 series0->setName("scatter1");
9 series0->setShape(QScatterSeries::MarkerShapeCircle);
10 series0->setShape(QScatterSeries::MarkerShapeCircle);
10 series0->setSize(15.0);
11 series0->setSize(15.0);
11
12
12 QScatterSeries *series1 = new QScatterSeries();
13 QScatterSeries *series1 = new QScatterSeries();
14 series1->setName("scatter2");
13 series1->setShape(QScatterSeries::MarkerShapeCircle);
15 series1->setShape(QScatterSeries::MarkerShapeCircle);
14 series1->setSize(20.0);
16 series1->setSize(20.0);
15 //![1]
17 //![1]
16
18
17 //![2]
19 //![2]
18 series0->append(0, 6);
20 series0->append(0, 6);
19 series0->append(2, 4);
21 series0->append(2, 4);
20 series0->append(3, 8);
22 series0->append(3, 8);
21 series0->append(7, 4);
23 series0->append(7, 4);
22 series0->append(10, 5);
24 series0->append(10, 5);
23
25
24 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
26 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
25 //![2]
27 //![2]
26
28
27 //![3]
29 //![3]
28 setRenderHint(QPainter::Antialiasing);
30 setRenderHint(QPainter::Antialiasing);
29 chart()->addSeries(series0);
31 chart()->addSeries(series0);
30 chart()->addSeries(series1);
32 chart()->addSeries(series1);
31 chart()->setTitle("Simple scatterchart example");
33 chart()->setTitle("Simple scatterchart example");
32 chart()->setBackgroundDropShadowEnabled(false);
34 chart()->setBackgroundDropShadowEnabled(false);
33 //![3]
35 //![3]
34 }
36 }
@@ -1,58 +1,60
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 #include "chartview.h"
21 #include "chartview.h"
22
22
23 QTCOMMERCIALCHART_USE_NAMESPACE
23 QTCOMMERCIALCHART_USE_NAMESPACE
24
24
25 ChartView::ChartView(QWidget *parent)
25 ChartView::ChartView(QWidget *parent)
26 : QChartView(new QChart(), parent),
26 : QChartView(new QChart(), parent),
27 m_scatter(0),
27 m_scatter(0),
28 m_scatter2(0)
28 m_scatter2(0)
29 {
29 {
30 setRenderHint(QPainter::Antialiasing);
30 setRenderHint(QPainter::Antialiasing);
31
31
32 chart()->setTitle("Click to interact with scatter points");
32 chart()->setTitle("Click to interact with scatter points");
33
33
34 m_scatter = new QScatterSeries();
34 m_scatter = new QScatterSeries();
35 m_scatter->setName("scatter1");
35 for(qreal x(0.5); x <= 4.0; x += 0.5) {
36 for(qreal x(0.5); x <= 4.0; x += 0.5) {
36 for(qreal y(0.5); y <= 4.0; y += 0.5) {
37 for(qreal y(0.5); y <= 4.0; y += 0.5) {
37 *m_scatter << QPointF(x, y);
38 *m_scatter << QPointF(x, y);
38 }
39 }
39 }
40 }
40 m_scatter2 = new QScatterSeries();
41 m_scatter2 = new QScatterSeries();
42 m_scatter2->setName("scatter2");
41
43
42 chart()->addSeries(m_scatter2);
44 chart()->addSeries(m_scatter2);
43 chart()->addSeries(m_scatter);
45 chart()->addSeries(m_scatter);
44 chart()->axisX()->setRange(0, 4.5);
46 chart()->axisX()->setRange(0, 4.5);
45 chart()->axisY()->setRange(0, 4.5);
47 chart()->axisY()->setRange(0, 4.5);
46
48
47 connect(m_scatter, SIGNAL(clicked(QPointF)), this, SLOT(handleClickedPoint(QPointF)));
49 connect(m_scatter, SIGNAL(clicked(QPointF)), this, SLOT(handleClickedPoint(QPointF)));
48 }
50 }
49
51
50 ChartView::~ChartView()
52 ChartView::~ChartView()
51 {
53 {
52 }
54 }
53
55
54 void ChartView::handleClickedPoint(const QPointF& point)
56 void ChartView::handleClickedPoint(const QPointF& point)
55 {
57 {
56 m_scatter->remove(point);
58 m_scatter->remove(point);
57 m_scatter2->append(point);
59 m_scatter2->append(point);
58 }
60 }
@@ -1,65 +1,66
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 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QSplineSeries>
24 #include <QSplineSeries>
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
27
28 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
29 {
29 {
30 QApplication a(argc, argv);
30 QApplication a(argc, argv);
31
31
32 //![1]
32 //![1]
33 QSplineSeries* series = new QSplineSeries();
33 QSplineSeries* series = new QSplineSeries();
34 series->setName("spline");
34 //![1]
35 //![1]
35
36
36 //![2]
37 //![2]
37 series->append(0, 6);
38 series->append(0, 6);
38 series->append(2, 4);
39 series->append(2, 4);
39 series->append(3, 8);
40 series->append(3, 8);
40 series->append(7, 4);
41 series->append(7, 4);
41 series->append(10, 5);
42 series->append(10, 5);
42 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
43 *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
43 //![2]
44 //![2]
44
45
45 //![3]
46 //![3]
46 QChart* chart = new QChart();
47 QChart* chart = new QChart();
47 chart->addSeries(series);
48 chart->addSeries(series);
48 chart->setTitle("Simple spline chart example");
49 chart->setTitle("Simple spline chart example");
49 chart->axisY()->setRange(0, 10);
50 chart->axisY()->setRange(0, 10);
50 //![3]
51 //![3]
51
52
52 //![4]
53 //![4]
53 QChartView* chartView = new QChartView(chart);
54 QChartView* chartView = new QChartView(chart);
54 chartView->setRenderHint(QPainter::Antialiasing);
55 chartView->setRenderHint(QPainter::Antialiasing);
55 //![4]
56 //![4]
56
57
57 //![5]
58 //![5]
58 QMainWindow window;
59 QMainWindow window;
59 window.setCentralWidget(chartView);
60 window.setCentralWidget(chartView);
60 window.resize(400, 300);
61 window.resize(400, 300);
61 window.show();
62 window.show();
62 //![5]
63 //![5]
63
64
64 return a.exec();
65 return a.exec();
65 }
66 }
@@ -1,59 +1,60
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 #include "chart.h"
21 #include "chart.h"
22 #include "chartview.h"
22 #include "chartview.h"
23 #include <QApplication>
23 #include <QApplication>
24 #include <QMainWindow>
24 #include <QMainWindow>
25 #include <QLineSeries>
25 #include <QLineSeries>
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
30 {
30 {
31 QApplication a(argc, argv);
31 QApplication a(argc, argv);
32
32
33 //![1]
33 //![1]
34 QLineSeries* series = new QLineSeries();
34 QLineSeries* series = new QLineSeries();
35 series->setName("line");
35 qreal yValue = 0.0;
36 qreal yValue = 0.0;
36 for (int i(0); i < 500; i++) {
37 for (int i(0); i < 500; i++) {
37 yValue = yValue + (qreal) (qrand() % 10) / 500.0;
38 yValue = yValue + (qreal) (qrand() % 10) / 500.0;
38 QPointF value((i + (qreal) rand() / (qreal) RAND_MAX) * (10.0 / 500.0), yValue);
39 QPointF value((i + (qreal) rand() / (qreal) RAND_MAX) * (10.0 / 500.0), yValue);
39 *series << value;
40 *series << value;
40 }
41 }
41 //![1]
42 //![1]
42
43
43 Chart* chart = new Chart();
44 Chart* chart = new Chart();
44 chart->addSeries(series);
45 chart->addSeries(series);
45 chart->setTitle("Zoom in/out example");
46 chart->setTitle("Zoom in/out example");
46 chart->setAnimationOptions(QChart::SeriesAnimations);
47 chart->setAnimationOptions(QChart::SeriesAnimations);
47
48
48 ChartView* chartView = new ChartView(chart);
49 ChartView* chartView = new ChartView(chart);
49 chartView->setRenderHint(QPainter::Antialiasing);
50 chartView->setRenderHint(QPainter::Antialiasing);
50
51
51 QMainWindow window;
52 QMainWindow window;
52 window.setCentralWidget(chartView);
53 window.setCentralWidget(chartView);
53 window.resize(400, 300);
54 window.resize(400, 300);
54 window.grabGesture(Qt::PanGesture);
55 window.grabGesture(Qt::PanGesture);
55 window.grabGesture(Qt::PinchGesture);
56 window.grabGesture(Qt::PinchGesture);
56 window.show();
57 window.show();
57
58
58 return a.exec();
59 return a.exec();
59 }
60 }
General Comments 0
You need to be logged in to leave comments. Login now