@@ -1,75 +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 "chart.h" |
|
22 | 22 | #include <QChartAxis> |
|
23 | 23 | #include <QSplineSeries> |
|
24 | 24 | #include <QTime> |
|
25 | 25 | |
|
26 | 26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
27 | 27 | :QChart(parent, wFlags), |
|
28 | 28 | m_step(1), |
|
29 | 29 | m_x(0), |
|
30 | 30 | m_y(1) |
|
31 | 31 | { |
|
32 |
|
|
|
33 | qsrand((uint)now.msec()); | |
|
32 | qsrand((uint) QTime::currentTime().msec()); | |
|
34 | 33 | |
|
35 | 34 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); |
|
36 | 35 | m_timer.setInterval(1000); |
|
37 | 36 | |
|
38 |
m_series |
|
|
39 | QPen blue(Qt::blue); | |
|
40 | blue.setWidth(3); | |
|
41 | m_series0->setPen(blue); | |
|
42 | ||
|
43 | m_series1 = new QSplineSeries(this); | |
|
37 | m_series = new QSplineSeries(this); | |
|
44 | 38 | QPen green(Qt::red); |
|
45 | 39 | green.setWidth(3); |
|
46 |
m_series |
|
|
40 | m_series->setPen(green); | |
|
41 | m_series->append(m_x, m_y); | |
|
47 | 42 | |
|
48 | m_series0->append(m_x, m_y); | |
|
49 | m_series1->append(m_x, m_y); | |
|
43 | addSeries(m_series); | |
|
50 | 44 | |
|
51 | addSeries(m_series0); | |
|
52 | addSeries(m_series1); | |
|
53 | 45 | axisY()->setRange(-5, 5); |
|
54 | 46 | axisX()->setRange(-9, 1); |
|
55 | 47 | axisX()->setTicksCount(11); |
|
48 | ||
|
56 | 49 | m_timer.start(); |
|
57 | 50 | } |
|
58 | 51 | |
|
59 | 52 | Chart::~Chart() |
|
60 | 53 | { |
|
61 | 54 | |
|
62 | 55 | } |
|
63 | 56 | |
|
64 | 57 | void Chart::handleTimeout() |
|
65 | 58 | { |
|
66 | 59 | m_x += m_step; |
|
67 | 60 | m_y = qrand() % 5 - 2.5; |
|
68 |
m_series |
|
|
69 | m_series1->append(m_x, m_y); | |
|
70 | if (m_x >= 10) { | |
|
71 | m_series0->remove(m_x - 10); | |
|
72 | m_series1->remove(m_x - 10); | |
|
73 | } | |
|
61 | m_series->append(m_x, m_y); | |
|
62 | if (m_x >= 10) | |
|
63 | m_series->remove(m_x - 10); | |
|
74 | 64 | scrollRight(); |
|
75 | 65 | } |
@@ -1,56 +1,54 | |||
|
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 CHART_H_ |
|
22 | 22 | #define CHART_H_ |
|
23 | 23 | |
|
24 | 24 | #include <QChart> |
|
25 | 25 | #include <QTimer> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | class QSplineSeries; |
|
29 | class QLineSeries; | |
|
30 | 29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | 30 | |
|
32 | 31 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | 32 | |
|
34 | 33 | //![1] |
|
35 | 34 | class Chart: public QChart |
|
36 | 35 | { |
|
37 | 36 | Q_OBJECT |
|
38 | 37 | public: |
|
39 | 38 | Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
40 | 39 | virtual ~Chart(); |
|
41 | 40 | |
|
42 | 41 | public slots: |
|
43 | 42 | void handleTimeout(); |
|
44 | 43 | |
|
45 | 44 | private: |
|
46 | 45 | QTimer m_timer; |
|
47 |
Q |
|
|
48 | QSplineSeries* m_series1; | |
|
46 | QSplineSeries* m_series; | |
|
49 | 47 | QStringList m_titles; |
|
50 | 48 | qreal m_step; |
|
51 | 49 | qreal m_x; |
|
52 | 50 | qreal m_y; |
|
53 | 51 | }; |
|
54 | 52 | //![1] |
|
55 | 53 | |
|
56 | 54 | #endif /* CHART_H_ */ |
@@ -1,6 +1,6 | |||
|
1 | 1 | !include( ../examples.pri ) { |
|
2 | 2 | error( "Couldn't find the examples.pri file!" ) |
|
3 | 3 | } |
|
4 | TARGET = ekgchart | |
|
4 | TARGET = dynamicspline | |
|
5 | 5 | HEADERS += chart.h |
|
6 | 6 | SOURCES += main.cpp chart.cpp |
@@ -1,41 +1,41 | |||
|
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 <QChartView> |
|
23 | 23 | #include <QApplication> |
|
24 | 24 | #include <QMainWindow> |
|
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 | QMainWindow window; |
|
32 | 32 | Chart *chart = new Chart; |
|
33 |
chart->setTitle(" |
|
|
33 | chart->setTitle("Dynamic spline chart"); | |
|
34 | 34 | chart->setAnimationOptions(QChart::AllAnimations); |
|
35 | 35 | QChartView chartView(chart); |
|
36 | 36 | chartView.setRenderHint(QPainter::Antialiasing); |
|
37 | 37 | window.setCentralWidget(&chartView); |
|
38 | 38 | window.resize(400, 300); |
|
39 | 39 | window.show(); |
|
40 | 40 | return a.exec(); |
|
41 | 41 | } |
@@ -1,26 +1,26 | |||
|
1 | 1 | TEMPLATE = subdirs |
|
2 | 2 | SUBDIRS += \ |
|
3 | 3 | areachart \ |
|
4 | 4 | barchart \ |
|
5 | 5 | customchart \ |
|
6 | ekgchart \ | |
|
6 | dynamicspline \ | |
|
7 | 7 | linechart \ |
|
8 | 8 | percentbarchart \ |
|
9 | 9 | piechart \ |
|
10 | 10 | piechartdrilldown \ |
|
11 | 11 | presenterchart \ |
|
12 | 12 | scatterchart \ |
|
13 | 13 | scatterinteractions \ |
|
14 | 14 | splinechart \ |
|
15 | 15 | stackedbarchart \ |
|
16 | 16 | stackedbarchartdrilldown \ |
|
17 | 17 | zoomlinechart \ |
|
18 | 18 | modeldata |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 |
General Comments 0
You need to be logged in to leave comments.
Login now