##// 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
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
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 bullet_sq.png \
22 bullet_sq.png \
23 bullet_up.png \
23 bullet_up.png \
24 horBar.png \
24 horBar.png \
25 presenterchart_example.png \
25 bg.png
26 bg.png
26
27
27
28
@@ -15,13 +15,14
15 <ul>
15 <ul>
16 <li><a href="example-areachart.html">Area Chart example</a></li>
16 <li><a href="example-areachart.html">Area Chart example</a></li>
17 <li><a href="example-barchart.html">Bar Chart example</a></li>
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 <li><a href="example-linechart.html">Line Chart example</a></li>
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 <li><a href="example-piechart.html">Pie Chart example</a></li>
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 <li><a href="example-splinechart.html">Spline Chart example</a></li>
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 </ul>
26 </ul>
26 </td>
27 </td>
27 </tr>
28 </tr>
@@ -35,6 +35,7
35 </tr>
35 </tr>
36 <tr>
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 </tr>
39 </tr>
39 </table>
40 </table>
40 </div>
41 </div>
@@ -7,28 +7,32
7 ChartView::ChartView(QWidget* parent):QChartView(parent),
7 ChartView::ChartView(QWidget* parent):QChartView(parent),
8 m_index(0)
8 m_index(0)
9 {
9 {
10 QTime now = QTime::currentTime();
11 qsrand((uint)now.msec());
10 setChartTitle("Three random line charts");
12 setChartTitle("Three random line charts");
11
13
12 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
14 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
13 m_timer.setInterval(3000);
15 m_timer.setInterval(3000);
14
16
15 QTime now = QTime::currentTime();
17 //![1]
16 qsrand((uint)now.msec());
17
18 QLineSeries* series0 = new QLineSeries(this);
18 QLineSeries* series0 = new QLineSeries(this);
19 QPen blue(Qt::blue);
19 QPen blue(Qt::blue);
20 blue.setWidth(3);
20 blue.setWidth(3);
21 series0->setPen(blue);
21 series0->setPen(blue);
22
22 QScatterSeries* series1 = new QScatterSeries(this);
23 QScatterSeries* series1 = new QScatterSeries(this);
23 QPen red(Qt::red);
24 QPen red(Qt::red);
24 red.setWidth(3);
25 red.setWidth(3);
25 series1->setPen(red);
26 series1->setPen(red);
26 series1->setBrush(Qt::white);
27 series1->setBrush(Qt::white);
28
27 QSplineSeries* series2 = new QSplineSeries(this);
29 QSplineSeries* series2 = new QSplineSeries(this);
28 QPen green(Qt::green);
30 QPen green(Qt::green);
29 green.setWidth(3);
31 green.setWidth(3);
30 series2->setPen(green);
32 series2->setPen(green);
33 //![1]
31
34
35 //![2]
32 int numPoints = 10;
36 int numPoints = 10;
33
37
34 for (int x = 0; x <= numPoints; ++x) {
38 for (int x = 0; x <= numPoints; ++x) {
@@ -37,14 +41,16 m_index(0)
37 series1->add(x,y);
41 series1->add(x,y);
38 series2->add(x,y);
42 series2->add(x,y);
39 }
43 }
44 //![2]
40
45
46 //![3]
41 m_series<<series0;
47 m_series<<series0;
42 m_titles<<chartTitle()+": LineChart";
48 m_titles<<chartTitle()+": LineChart";
43 m_series<<series1;
49 m_series<<series1;
44 m_titles<<chartTitle()+": ScatterChart";
50 m_titles<<chartTitle()+": ScatterChart";
45 m_series<<series2;
51 m_series<<series2;
46 m_titles<<chartTitle()+": SplineChart";
52 m_titles<<chartTitle()+": SplineChart";
47
53 //![3]
48 addSeries(series0);
54 addSeries(series0);
49 setChartTitle(m_titles.at(0));
55 setChartTitle(m_titles.at(0));
50
56
@@ -58,13 +64,14 ChartView::~ChartView()
58 qDeleteAll(m_series);
64 qDeleteAll(m_series);
59 }
65 }
60
66
67 //![4]
61 void ChartView::handleTimeout()
68 void ChartView::handleTimeout()
62 {
69 {
63 if(m_series.size()==0) return;
70 if(m_series.size()==0) return;
64
65 removeSeries(m_series.at(m_index));
71 removeSeries(m_series.at(m_index));
66 m_index++;
72 m_index++;
67 m_index=m_index%m_series.size();
73 m_index=m_index%m_series.size();
68 addSeries(m_series.at(m_index));
74 addSeries(m_series.at(m_index));
69 setChartTitle(m_titles.at(m_index));
75 setChartTitle(m_titles.at(m_index));
70 }
76 }
77 //![4]
@@ -6,6 +6,7
6
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
8
9 //![1]
9 class ChartView: public QChartView
10 class ChartView: public QChartView
10 {
11 {
11 Q_OBJECT
12 Q_OBJECT
@@ -22,5 +23,6 private:
22 QStringList m_titles;
23 QStringList m_titles;
23 int m_index;
24 int m_index;
24 };
25 };
26 //![1]
25
27
26 #endif /* CHARTVIEW_H_ */
28 #endif /* CHARTVIEW_H_ */
@@ -1,6 +1,6
1 !include( ../example.pri ) {
1 !include( ../example.pri ) {
2 error( "Couldn't find the example.pri file!" )
2 error( "Couldn't find the example.pri file!" )
3 }
3 }
4 TARGET = presenterChart
4 TARGET = presenterchart
5 HEADERS += chartview.h
5 HEADERS += chartview.h
6 SOURCES += main.cpp chartview.cpp No newline at end of file
6 SOURCES += main.cpp chartview.cpp
General Comments 0
You need to be logged in to leave comments. Login now