@@ -1,29 +1,29 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | SUBDIRS += \ |
|
2 | SUBDIRS += \ | |
3 | areachart \ |
|
3 | areachart \ | |
4 | barchart \ |
|
4 | barchart \ | |
5 | #chartview \ |
|
5 | #chartview \ | |
6 | customchart \ |
|
6 | customchart \ | |
7 | #dynamiclinechart \ |
|
7 | #dynamiclinechart \ | |
8 | #ekgchart \ |
|
8 | #ekgchart \ | |
9 | linechart \ |
|
9 | linechart \ | |
10 | #multichart \ |
|
10 | #multichart \ | |
11 | percentbarchart \ |
|
11 | percentbarchart \ | |
12 | piechart \ |
|
12 | piechart \ | |
13 | piechartdrilldown \ |
|
13 | piechartdrilldown \ | |
14 | #presenterchart \ |
|
14 | #presenterchart \ | |
15 | scatterchart \ |
|
15 | scatterchart \ | |
16 | scatterinteractions \ |
|
16 | scatterinteractions \ | |
17 |
|
|
17 | splinechart \ | |
18 | stackedbarchart \ |
|
18 | stackedbarchart \ | |
19 | stackedbarchartdrilldown \ |
|
19 | stackedbarchartdrilldown \ | |
20 | #tablemodelchart \ |
|
20 | #tablemodelchart \ | |
21 | zoomlinechart |
|
21 | zoomlinechart | |
22 |
|
22 | |||
23 |
|
23 | |||
24 |
|
24 | |||
25 |
|
25 | |||
26 |
|
26 | |||
27 |
|
27 | |||
28 |
|
28 | |||
29 |
|
29 |
@@ -1,136 +1,137 | |||||
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 "splinewidget.h" |
|
21 | #include "splinewidget.h" | |
22 | #include "qchartview.h" |
|
22 | #include "qchartview.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include <QGridLayout> |
|
24 | #include <QGridLayout> | |
25 | #include <QPushButton> |
|
25 | #include <QPushButton> | |
26 | #include "qchartaxis.h" |
|
26 | #include "qchartaxis.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 | #include <QTime> |
|
28 | #include <QTime> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | SplineWidget::SplineWidget(QWidget *parent) |
|
32 | SplineWidget::SplineWidget(QWidget *parent) | |
33 | : QWidget(parent) |
|
33 | : QWidget(parent) | |
34 | { |
|
34 | { | |
35 | // qsrand(time(NULL)); |
|
35 | // qsrand(time(NULL)); | |
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
36 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
37 | //! [1] |
|
37 | //! [1] | |
38 | //create QSplineSeries |
|
38 | //create QSplineSeries | |
39 | series = new QSplineSeries(this); |
|
39 | series = new QSplineSeries(this); | |
40 | //! [1] |
|
40 | //! [1] | |
41 |
|
41 | |||
42 | //! [2] |
|
42 | //! [2] | |
43 | // customize the series presentation settings |
|
43 | // customize the series presentation settings | |
44 | QPen seriesPen(Qt::blue); |
|
44 | QPen seriesPen(Qt::blue); | |
45 | seriesPen.setWidth(3); |
|
45 | seriesPen.setWidth(3); | |
46 | // series->setPen(seriesPen); |
|
46 | // series->setPen(seriesPen); | |
47 | //! [2] |
|
47 | //! [2] | |
48 |
|
48 | |||
49 | //! [add points to series] |
|
49 | //! [add points to series] | |
50 | //add data points to the series |
|
50 | //add data points to the series | |
51 | series->append(QPointF(150, 100)); |
|
51 | series->append(QPointF(150, 100)); | |
52 | series->append(QPointF(200, 130)); |
|
52 | series->append(QPointF(200, 130)); | |
53 | series->append(QPointF(250, 120)); |
|
53 | series->append(QPointF(250, 120)); | |
54 | series->append(QPointF(300, 140)); |
|
54 | series->append(QPointF(300, 140)); | |
55 | series->append(QPointF(350, 160)); |
|
55 | series->append(QPointF(350, 160)); | |
56 | //! [add points to series] |
|
56 | //! [add points to series] | |
57 |
|
57 | |||
58 | QSplineSeries* series2 = new QSplineSeries; |
|
58 | QSplineSeries* series2 = new QSplineSeries; | |
59 |
|
59 | |||
60 | series2->append(QPointF(400, 120)); |
|
60 | series2->append(QPointF(400, 120)); | |
61 | series2->append(QPointF(450, 150)); |
|
61 | series2->append(QPointF(450, 150)); | |
62 | series2->append(QPointF(500, 145)); |
|
62 | series2->append(QPointF(500, 145)); | |
63 | series2->append(QPointF(550, 170)); |
|
63 | series2->append(QPointF(550, 170)); | |
64 |
|
64 | |||
65 | // series->append(QPointF(600, 190)); |
|
65 | // series->append(QPointF(600, 190)); | |
66 | // series->append(QPointF(650, 210)); |
|
66 | // series->append(QPointF(650, 210)); | |
67 | // series->append(QPointF(700, 190)); |
|
67 | // series->append(QPointF(700, 190)); | |
68 | // series->append(QPointF(750, 180)); |
|
68 | // series->append(QPointF(750, 180)); | |
69 | // series->append(QPointF(800, 170)); |
|
69 | // series->append(QPointF(800, 170)); | |
70 | QSplineSeries* series3 = new QSplineSeries; |
|
70 | QSplineSeries* series3 = new QSplineSeries; | |
71 | series3->append(QPointF(600, 190)); |
|
71 | series3->append(QPointF(600, 190)); | |
72 | series3->append(QPointF(650, 210)); |
|
72 | series3->append(QPointF(650, 210)); | |
73 | series3->append(QPointF(700, 190)); |
|
73 | series3->append(QPointF(700, 190)); | |
74 | series3->append(QPointF(750, 180)); |
|
74 | series3->append(QPointF(750, 180)); | |
75 | series3->append(QPointF(800, 170)); |
|
75 | series3->append(QPointF(800, 170)); | |
76 |
|
76 | |||
77 | //! [3] |
|
77 | //! [3] | |
78 | // create chart view |
|
78 | // create chart view | |
79 |
QChart |
|
79 | QChart* chart = new QChart; | |
80 | chart->addSeries(series); |
|
80 | chart->addSeries(series); | |
81 | chart->addSeries(series2); |
|
81 | chart->addSeries(series2); | |
82 | chart->addSeries(series3); |
|
82 | chart->addSeries(series3); | |
83 |
|
83 | |||
84 |
chart->set |
|
84 | chart->setTitle("Spline chart example"); | |
85 | chart->axisX()->setMax(1500); |
|
85 | chart->axisX()->setMax(1500); | |
86 | chart->axisY()->setMax(500); |
|
86 | chart->axisY()->setMax(500); | |
87 |
|
87 | |||
88 | chart->setMinimumSize(800,600); |
|
88 | chart->setMinimumSize(800,600); | |
89 | //! [3] |
|
89 | //! [3] | |
90 |
|
90 | |||
91 | //! [4] |
|
91 | //! [4] | |
92 | //add new data point button |
|
92 | //add new data point button | |
93 | QPushButton* addButton = new QPushButton("Add new point"); |
|
93 | QPushButton* addButton = new QPushButton("Add new point"); | |
94 | connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint())); |
|
94 | connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint())); | |
95 |
|
95 | |||
96 | // remove the last data point in the series |
|
96 | // remove the last data point in the series | |
97 | QPushButton* removeButton = new QPushButton("Remove point"); |
|
97 | QPushButton* removeButton = new QPushButton("Remove point"); | |
98 | connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint())); |
|
98 | connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint())); | |
99 | //! [4] |
|
99 | //! [4] | |
100 |
|
100 | |||
101 | //! [5] |
|
101 | //! [5] | |
102 | //butttons layout |
|
102 | //butttons layout | |
103 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
103 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
104 | buttonsLayout->addWidget(addButton); |
|
104 | buttonsLayout->addWidget(addButton); | |
105 | buttonsLayout->addWidget(removeButton); |
|
105 | buttonsLayout->addWidget(removeButton); | |
106 | buttonsLayout->addStretch(); |
|
106 | buttonsLayout->addStretch(); | |
107 |
|
107 | |||
108 | QGridLayout* mainLayout = new QGridLayout; |
|
108 | QGridLayout* mainLayout = new QGridLayout; | |
109 | mainLayout->addWidget(chart, 1, 0); |
|
109 | QChartView *chartView = new QChartView(chart); | |
|
110 | mainLayout->addWidget(chartView, 1, 0); | |||
110 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
111 | mainLayout->addLayout(buttonsLayout, 1, 1); | |
111 | setLayout(mainLayout); |
|
112 | setLayout(mainLayout); | |
112 | //! [5] |
|
113 | //! [5] | |
113 | } |
|
114 | } | |
114 |
|
115 | |||
115 | //! [add point] |
|
116 | //! [add point] | |
116 | void SplineWidget::addNewPoint() |
|
117 | void SplineWidget::addNewPoint() | |
117 | { |
|
118 | { | |
118 | if (series->count() > 0) |
|
119 | if (series->count() > 0) | |
119 | series->append(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100))); |
|
120 | series->append(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100))); | |
120 | else |
|
121 | else | |
121 | series->append(QPointF(50, 50 + qrand()%50)); |
|
122 | series->append(QPointF(50, 50 + qrand()%50)); | |
122 | } |
|
123 | } | |
123 | //! [add point] |
|
124 | //! [add point] | |
124 |
|
125 | |||
125 | //! [remove point] |
|
126 | //! [remove point] | |
126 | void SplineWidget::removePoint() |
|
127 | void SplineWidget::removePoint() | |
127 | { |
|
128 | { | |
128 | if (series->count() > 0) |
|
129 | if (series->count() > 0) | |
129 | series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1))); |
|
130 | series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1))); | |
130 | } |
|
131 | } | |
131 | //! [remove point] |
|
132 | //! [remove point] | |
132 |
|
133 | |||
133 | SplineWidget::~SplineWidget() |
|
134 | SplineWidget::~SplineWidget() | |
134 | { |
|
135 | { | |
135 |
|
136 | |||
136 | } |
|
137 | } |
General Comments 0
You need to be logged in to leave comments.
Login now