@@ -0,0 +1,34 | |||
|
1 | #include "chartview.h" | |
|
2 | #include <QScatterSeries> | |
|
3 | ||
|
4 | ChartView::ChartView(QWidget *parent) : | |
|
5 | QChartView(new QChart(), parent) | |
|
6 | { | |
|
7 | //![1] | |
|
8 | QScatterSeries *series0 = new QScatterSeries(); | |
|
9 | series0->setShape(QScatterSeries::MarkerShapeCircle); | |
|
10 | series0->setSize(15.0); | |
|
11 | ||
|
12 | QScatterSeries *series1 = new QScatterSeries(); | |
|
13 | series1->setShape(QScatterSeries::MarkerShapeCircle); | |
|
14 | series1->setSize(20.0); | |
|
15 | //![1] | |
|
16 | ||
|
17 | //![2] | |
|
18 | series0->append(0, 6); | |
|
19 | series0->append(2, 4); | |
|
20 | series0->append(3, 8); | |
|
21 | series0->append(7, 4); | |
|
22 | series0->append(10, 5); | |
|
23 | ||
|
24 | *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2); | |
|
25 | //![2] | |
|
26 | ||
|
27 | //![3] | |
|
28 | setRenderHint(QPainter::Antialiasing); | |
|
29 | chart()->addSeries(series0); | |
|
30 | chart()->addSeries(series1); | |
|
31 | chart()->setTitle("Simple scatterchart example"); | |
|
32 | chart()->setBackgroundDropShadowEnabled(false); | |
|
33 | //![3] | |
|
34 | } |
@@ -0,0 +1,20 | |||
|
1 | #ifndef CHARTVIEW_H | |
|
2 | #define CHARTVIEW_H | |
|
3 | ||
|
4 | #include <QChartView> | |
|
5 | ||
|
6 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
7 | ||
|
8 | class ChartView : public QChartView | |
|
9 | { | |
|
10 | Q_OBJECT | |
|
11 | public: | |
|
12 | explicit ChartView(QWidget *parent = 0); | |
|
13 | ||
|
14 | signals: | |
|
15 | ||
|
16 | public slots: | |
|
17 | ||
|
18 | }; | |
|
19 | ||
|
20 | #endif // CHARTVIEW_H |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,48 +1,39 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/presenterchart |
|
3 | 3 | \title PresenterChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create chart which presents the same set of data as line, scatter, spline and area charts. |
|
7 | 7 | ChartPresenter will switch between these four chart types every few seconds. Note: You can also use the |
|
8 | 8 | QAbstractItemModel related APIs to pass data for the different series types. See the \l {Model data example} for |
|
9 | 9 | more details. |
|
10 | 10 | |
|
11 | 11 | \image examples_presenterchart1.png |
|
12 | 12 | \image examples_presenterchart2.png |
|
13 | 13 | \image examples_presenterchart3.png |
|
14 | 14 | \image examples_presenterchart4.png |
|
15 | ||
|
15 | ||
|
16 | 16 | We create simple ChartView class which derives form QChartView. |
|
17 | ||
|
17 | ||
|
18 | 18 | \snippet ../examples/presenterchart/chartview.h 1 |
|
19 | ||
|
19 | ||
|
20 | 20 | Class will implement \c handleTimeout() slot which we are going to use to trigger switching between different chart presentations. |
|
21 | 21 | We are also going to provide \c handlePoitClicked() slot which will show clicked point on the chart. |
|
22 | 22 | 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 |
|
23 | 23 | using QLineSeries , as scatter chart using QScatterSeries, as a spline chart using QSplineSeries and a area chart using QAreaSeries. We create needed instances in constructor of ChartView class. |
|
24 | 24 | We set custom line and points colors. |
|
25 | 25 | |
|
26 | 26 | \snippet ../examples/presenterchart/chartview.cpp 1 |
|
27 | 27 | |
|
28 | 28 | We add data to three series. Please note area chart is going to use QLineSeries as the upper line. We can use add() member function. |
|
29 | 29 | |
|
30 | 30 | \snippet ../examples/presenterchart/chartview.cpp 2 |
|
31 | 31 | |
|
32 | 32 | In the end we store references all the created series and matching titles. |
|
33 | 33 | |
|
34 | 34 | \snippet ../examples/presenterchart/chartview.cpp 3 |
|
35 | ||
|
36 | We connect \c clicked() signals from each series with our \c handlePointClciked() slot. | |
|
37 | ||
|
38 | \snippet ../examples/presenterchart/chartview.cpp 4 | |
|
39 | ||
|
35 | ||
|
40 | 36 | 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. |
|
41 | ||
|
42 |
\snippet ../examples/presenterchart/chartview.cpp |
|
|
43 | ||
|
44 | In \c handlePointClciked() slot we set the chart's title to show clicked point x and y coordinates. | |
|
45 | ||
|
46 | \snippet ../examples/presenterchart/chartview.cpp 6 | |
|
47 | ||
|
37 | ||
|
38 | \snippet ../examples/presenterchart/chartview.cpp 4 | |
|
48 | 39 | */ |
@@ -1,26 +1,27 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example examples/scatterchart |
|
3 | 3 | \title ScatterChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple scatter chart. |
|
7 | 7 | |
|
8 | 8 | \image examples_scatterchart.png |
|
9 | 9 | |
|
10 | 10 | To create scatter charts, QScatterSeries instance is needed. Here we create scatter series instance and we set the type, color and width of outline for scatter points. |
|
11 | 11 | |
|
12 |
\snippet ../examples/scatterchart/ |
|
|
12 | \snippet ../examples/scatterchart/chartview.cpp 1 | |
|
13 | 13 | |
|
14 | 14 | We add data to be shown. We can use add() member function or use stream operator. |
|
15 | 15 | |
|
16 |
\snippet ../examples/scatterchart/ |
|
|
16 | \snippet ../examples/scatterchart/chartview.cpp 2 | |
|
17 | 17 | |
|
18 | In the end we create QChartView instance, set title, set anti-aliasing and add scatter series. | |
|
18 | In the end we enable anti-aliasing, set the chart title and add the scatter series onto the chart. We also disable | |
|
19 | drop shadow, because it would not look good on an application with only chart view shown. | |
|
19 | 20 | |
|
20 |
\snippet ../examples/scatterchart/ |
|
|
21 | \snippet ../examples/scatterchart/chartview.cpp 3 | |
|
21 | 22 | |
|
22 | 23 | Chart is ready to be shown. |
|
23 | 24 | |
|
24 |
\snippet ../examples/scatterchart/main.cpp 4 |
|
|
25 | \snippet ../examples/scatterchart/main.cpp 4 | |
|
25 | 26 | |
|
26 | 27 | */ |
@@ -1,116 +1,105 | |||
|
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 | m_chart->setBackgroundDropShadowEnabled(false); | |
|
32 | 33 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); |
|
33 | 34 | m_timer.setInterval(3000); |
|
34 | 35 | |
|
35 | 36 | //![1] |
|
36 | 37 | QLineSeries* series0 = new QLineSeries(); |
|
37 | 38 | QPen blue(Qt::blue); |
|
38 | 39 | blue.setWidth(3); |
|
39 | 40 | series0->setPen(blue); |
|
40 | 41 | |
|
41 | 42 | QScatterSeries* series1 = new QScatterSeries(); |
|
42 | 43 | QPen red(Qt::red); |
|
43 | 44 | red.setWidth(3); |
|
44 | 45 | series1->setPen(red); |
|
45 | 46 | series1->setBrush(Qt::white); |
|
46 | 47 | |
|
47 | 48 | QSplineSeries* series2 = new QSplineSeries(); |
|
48 | 49 | QPen green(Qt::green); |
|
49 | 50 | green.setWidth(3); |
|
50 | 51 | series2->setPen(green); |
|
51 | 52 | |
|
52 | 53 | QAreaSeries* series3 = new QAreaSeries(series0); |
|
53 | 54 | QPen yellow(Qt::black); |
|
54 | 55 | yellow.setWidth(3); |
|
55 | 56 | series3->setPen(yellow); |
|
56 | 57 | series3->setBrush(Qt::yellow); |
|
57 | 58 | //![1] |
|
58 | 59 | |
|
59 | 60 | //![2] |
|
60 | 61 | int numPoints = 10; |
|
61 | 62 | |
|
62 | 63 | for (int x = 0; x <= numPoints; ++x) { |
|
63 | 64 | qreal y = qrand() % 100; |
|
64 | 65 | series0->append(x,y); |
|
65 | 66 | series1->append(x,y); |
|
66 | 67 | series2->append(x,y); |
|
67 | 68 | } |
|
68 | 69 | //![2] |
|
69 | 70 | |
|
70 | 71 | //![3] |
|
71 | 72 | m_series<<series0; |
|
72 | 73 | m_titles<< m_chart->title()+": LineChart"; |
|
73 | 74 | m_series<<series1; |
|
74 | 75 | m_titles<< m_chart->title()+": ScatterChart"; |
|
75 | 76 | m_series<<series2; |
|
76 | 77 | m_titles<< m_chart->title()+": SplineChart"; |
|
77 | 78 | m_series<<series3; |
|
78 | 79 | m_titles<< m_chart->title()+": AreaChart"; |
|
79 | 80 | //![3] |
|
80 | 81 | |
|
81 | //![4] | |
|
82 | foreach (QAbstractSeries* series, m_series) { | |
|
83 | QObject::connect(series,SIGNAL(clicked(QPointF)),this,SLOT(handlePointClicked(QPointF))); | |
|
84 | } | |
|
85 | //![4] | |
|
86 | 82 | m_timer.start(); |
|
87 | 83 | handleTimeout(); |
|
88 | 84 | } |
|
89 | 85 | |
|
90 | 86 | ChartView::~ChartView() |
|
91 | 87 | { |
|
92 | 88 | if(m_series.size()==0) return; |
|
93 | 89 | m_chart->removeSeries(m_series.at(m_index)); |
|
94 | 90 | m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone |
|
95 | 91 | qDeleteAll(m_series); |
|
96 | 92 | } |
|
97 | 93 | |
|
98 |
//![ |
|
|
94 | //![4] | |
|
99 | 95 | void ChartView::handleTimeout() |
|
100 | 96 | { |
|
101 | 97 | if(m_series.size()==0) return; |
|
102 | 98 | if(m_index>=0) |
|
103 | 99 | m_chart->removeSeries(m_series.at(m_index)); |
|
104 | 100 | m_index++; |
|
105 | 101 | m_index=m_index%m_series.size(); |
|
106 | 102 | m_chart->addSeries(m_series.at(m_index)); |
|
107 | 103 | m_chart->setTitle(m_titles.at(m_index)); |
|
108 | 104 | } |
|
109 |
//![ |
|
|
110 | ||
|
111 | //![6] | |
|
112 | void ChartView::handlePointClicked(const QPointF& point) | |
|
113 | { | |
|
114 | m_chart->setTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y())); | |
|
115 | } | |
|
116 | //![6] | |
|
105 | //![4] |
@@ -1,50 +1,49 | |||
|
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 | #ifndef CHARTVIEW_H_ |
|
22 | 22 | #define CHARTVIEW_H_ |
|
23 | 23 | |
|
24 | 24 | #include <QChartView> |
|
25 | 25 | #include <QTimer> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | //![1] |
|
30 | 30 | class ChartView: public QChartView |
|
31 | 31 | { |
|
32 | 32 | Q_OBJECT |
|
33 | 33 | public: |
|
34 | 34 | ChartView(QChart* chart,QWidget* parent = 0); |
|
35 | 35 | virtual ~ChartView(); |
|
36 | 36 | |
|
37 | 37 | public slots: |
|
38 | 38 | void handleTimeout(); |
|
39 | void handlePointClicked(const QPointF& point); | |
|
40 | 39 | |
|
41 | 40 | private: |
|
42 | 41 | QTimer m_timer; |
|
43 | 42 | QList<QAbstractSeries *> m_series; |
|
44 | 43 | QStringList m_titles; |
|
45 | 44 | int m_index; |
|
46 | 45 | QChart *m_chart; |
|
47 | 46 | }; |
|
48 | 47 | //![1] |
|
49 | 48 | |
|
50 | 49 | #endif /* CHARTVIEW_H_ */ |
@@ -1,39 +1,39 | |||
|
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 <QApplication> |
|
23 | 23 | #include <QMainWindow> |
|
24 | 24 | |
|
25 | 25 | int main(int argc, char *argv[]) |
|
26 | 26 | { |
|
27 | 27 | QApplication a(argc, argv); |
|
28 | 28 | QMainWindow window; |
|
29 | 29 | QChart* chart = new QChart(); |
|
30 | 30 | chart->axisX()->setNiceNumbersEnabled(true); |
|
31 | 31 | chart->axisY()->setNiceNumbersEnabled(true); |
|
32 | 32 | ChartView chartView(chart,&window); |
|
33 | 33 | chartView.setRenderHint(QPainter::Antialiasing); |
|
34 |
chart->setAnimationOptions(QChart:: |
|
|
34 | chart->setAnimationOptions(QChart::SeriesAnimations); | |
|
35 | 35 | window.setCentralWidget(&chartView); |
|
36 | 36 | window.resize(400, 300); |
|
37 | 37 | window.show(); |
|
38 | 38 | return a.exec(); |
|
39 | 39 | } |
@@ -1,82 +1,40 | |||
|
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 <QtGui/QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 |
#include |
|
|
24 | #include <QScatterSeries> | |
|
23 | #include "chartview.h" | |
|
25 | 24 | |
|
26 | 25 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | 26 | |
|
28 | 27 | int main(int argc, char *argv[]) |
|
29 | 28 | { |
|
30 | 29 | QApplication a(argc, argv); |
|
31 | 30 | |
|
32 | //![1] | |
|
33 | QPen pen(Qt::black); | |
|
34 | pen.setWidth(2); | |
|
35 | QBrush blue(Qt::blue); | |
|
36 | QBrush red(Qt::red); | |
|
37 | ||
|
38 | QScatterSeries *series0 = new QScatterSeries(); | |
|
39 | series0->setPen(pen); | |
|
40 | series0->setBrush(blue); | |
|
41 | series0->setShape(QScatterSeries::MarkerShapeCircle); | |
|
42 | series0->setSize(15.0); | |
|
43 | ||
|
44 | QScatterSeries *series1 = new QScatterSeries(); | |
|
45 | series1->setPen(pen); | |
|
46 | series1->setBrush(red); | |
|
47 | series1->setShape(QScatterSeries::MarkerShapeCircle); | |
|
48 | series1->setSize(15.0); | |
|
49 | //![1] | |
|
50 | ||
|
51 | //![2] | |
|
52 | series0->append(0, 6); | |
|
53 | series0->append(2, 4); | |
|
54 | series0->append(3, 8); | |
|
55 | series0->append(7, 4); | |
|
56 | series0->append(10, 5); | |
|
57 | ||
|
58 | *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2); | |
|
59 | //![2] | |
|
60 | ||
|
61 | //![3] | |
|
62 | QChart* chart = new QChart(); | |
|
63 | ||
|
64 | chart->addSeries(series0); | |
|
65 | chart->addSeries(series1); | |
|
66 | chart->setTitle("Simple scatterchart example"); | |
|
67 | //![3] | |
|
68 | ||
|
69 | //![4] | |
|
70 | QChartView* chartView = new QChartView(chart); | |
|
71 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
72 | 31 | //![4] |
|
73 | ||
|
74 | //![5] | |
|
32 | ChartView* chartView = new ChartView(); | |
|
75 | 33 | QMainWindow window; |
|
76 | 34 | window.setCentralWidget(chartView); |
|
77 | 35 | window.resize(400, 300); |
|
78 | 36 | window.show(); |
|
79 |
//![ |
|
|
37 | //![4] | |
|
80 | 38 | |
|
81 | 39 | return a.exec(); |
|
82 | 40 | } |
General Comments 0
You need to be logged in to leave comments.
Login now