##// END OF EJS Templates
Adds chartPresenter example to docs
Michal Klocek -
r482:e8dd9abb1675
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,37
1 /*!
2 \example example/presenterchart
3 \title PresenterChart Example
4 \subtitle
5
6 The example shows how to create chart which presents the same set of data as line, scatter and spline charts.
7 ChartPresenter will switch between these three chart types every few seconds.
8 Please note this example does not use common data model. A use of common data model is documented here.[TODO]
9
10 \image presenterchart1.png
11 \image presenterchart2.png
12 \image presenterchart3.png
13
14 We create simple ChartView class which derives form QChartView.
15
16 \snippet ../example/presenterchart/chartview.h 1
17
18 Class will implement \c handleTimeout() slot which we are going to use to trigger switching between different chart presentations.
19 Class members \c m_series and \c m_titles are going to store series and related titles. In example we are going to present data as a line chart
20 using QLineSeries , as scatter chart using QScatterSeries, and as a spline chart using QSplineSeries. We create needed instances in constructor of ChartView class.
21 We set custom line and points colors.
22
23 \snippet ../example/presenterchart/chartview.cpp 1
24
25 We add data to all three series. We can use add() member function. If data set is large,it is wiser to use shared data model, as described here.[TODO]
26
27 \snippet ../example/presenterchart/chartview.cpp 2
28
29 In the end we store references all the created series and matching titles.
30
31 \snippet ../example/presenterchart/chartview.cpp 3
32
33 In \c handleTimeout() slot we change currently displayed chart by removing previous series and adding next series from the \c m_series list. We also set proper title.
34
35 \snippet ../example/presenterchart/chartview.cpp 4
36
37 */ No newline at end of file
@@ -22,6 +22,7 extraimages.HTML = qt_commercial_logo.png \
22 22 bullet_sq.png \
23 23 bullet_up.png \
24 24 horBar.png \
25 presenterchart_example.png \
25 26 bg.png
26 27
27 28
@@ -15,13 +15,14
15 15 <ul>
16 16 <li><a href="example-areachart.html">Area Chart example</a></li>
17 17 <li><a href="example-barchart.html">Bar Chart example</a></li>
18 <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li>
19 <li><a href="example-percentbarchart.html">Percent Bar Chart example</a></li>
20 <li><a href="example-scatterchart.html">Scatter Chart example</a></li>
21 <li><a href="example-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown example</a></li>
22 18 <li><a href="example-linechart.html">Line Chart example</a></li>
19 <li><a href="example-percentbarchart.html">Percent Bar Chart example</a></li>
23 20 <li><a href="example-piechart.html">Pie Chart example</a></li>
21 <li><a href="example-presenterchart.html">Presenter Chart example</a></li>
22 <li><a href="example-scatterchart.html">Scatter Chart example</a></li>
24 23 <li><a href="example-splinechart.html">Spline Chart example</a></li>
24 <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li>
25 <li><a href="example-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown example</a></li>
25 26 </ul>
26 27 </td>
27 28 </tr>
@@ -34,7 +34,8
34 34 <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td>
35 35 </tr>
36 36 <tr>
37 <td><img src="images/chartview_example.jpg " alt="linechart" /></td>
37 <td><img src="images/chartview_example.jpg " alt="linechart" /></td>
38 <td><a href="example-presenterchart.html"><img src="images/presenterchart_example.png" alt="presenterchart" /></a></td>
38 39 </tr>
39 40 </table>
40 41 </div>
@@ -7,28 +7,32
7 7 ChartView::ChartView(QWidget* parent):QChartView(parent),
8 8 m_index(0)
9 9 {
10 QTime now = QTime::currentTime();
11 qsrand((uint)now.msec());
10 12 setChartTitle("Three random line charts");
11 13
12 14 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
13 15 m_timer.setInterval(3000);
14 16
15 QTime now = QTime::currentTime();
16 qsrand((uint)now.msec());
17
17 //![1]
18 18 QLineSeries* series0 = new QLineSeries(this);
19 19 QPen blue(Qt::blue);
20 20 blue.setWidth(3);
21 21 series0->setPen(blue);
22
22 23 QScatterSeries* series1 = new QScatterSeries(this);
23 24 QPen red(Qt::red);
24 25 red.setWidth(3);
25 26 series1->setPen(red);
26 27 series1->setBrush(Qt::white);
28
27 29 QSplineSeries* series2 = new QSplineSeries(this);
28 30 QPen green(Qt::green);
29 31 green.setWidth(3);
30 32 series2->setPen(green);
33 //![1]
31 34
35 //![2]
32 36 int numPoints = 10;
33 37
34 38 for (int x = 0; x <= numPoints; ++x) {
@@ -37,14 +41,16 m_index(0)
37 41 series1->add(x,y);
38 42 series2->add(x,y);
39 43 }
44 //![2]
40 45
46 //![3]
41 47 m_series<<series0;
42 48 m_titles<<chartTitle()+": LineChart";
43 49 m_series<<series1;
44 50 m_titles<<chartTitle()+": ScatterChart";
45 51 m_series<<series2;
46 52 m_titles<<chartTitle()+": SplineChart";
47
53 //![3]
48 54 addSeries(series0);
49 55 setChartTitle(m_titles.at(0));
50 56
@@ -58,13 +64,14 ChartView::~ChartView()
58 64 qDeleteAll(m_series);
59 65 }
60 66
67 //![4]
61 68 void ChartView::handleTimeout()
62 69 {
63 70 if(m_series.size()==0) return;
64
65 71 removeSeries(m_series.at(m_index));
66 72 m_index++;
67 73 m_index=m_index%m_series.size();
68 74 addSeries(m_series.at(m_index));
69 75 setChartTitle(m_titles.at(m_index));
70 76 }
77 //![4]
@@ -6,6 +6,7
6 6
7 7 QTCOMMERCIALCHART_USE_NAMESPACE
8 8
9 //![1]
9 10 class ChartView: public QChartView
10 11 {
11 12 Q_OBJECT
@@ -22,5 +23,6 private:
22 23 QStringList m_titles;
23 24 int m_index;
24 25 };
26 //![1]
25 27
26 28 #endif /* CHARTVIEW_H_ */
@@ -1,6 +1,6
1 1 !include( ../example.pri ) {
2 2 error( "Couldn't find the example.pri file!" )
3 3 }
4 TARGET = presenterChart
4 TARGET = presenterchart
5 5 HEADERS += chartview.h
6 6 SOURCES += main.cpp chartview.cpp No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now