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