@@ -1,58 +1,57 | |||||
1 | #include "chartview.h" |
|
1 | #include "chartview.h" | |
2 | #include <QSplineSeries> |
|
2 | #include <QSplineSeries> | |
3 | #include <QTime> |
|
3 | #include <QTime> | |
4 |
|
4 | |||
5 | ChartView::ChartView(QWidget* parent):QChartView(parent), |
|
5 | ChartView::ChartView(QWidget* parent):QChartView(parent), | |
6 | m_step(1), |
|
6 | m_step(1), | |
7 | m_x(0), |
|
7 | m_x(0), | |
8 | m_y(1) |
|
8 | m_y(1) | |
9 | { |
|
9 | { | |
10 | QTime now = QTime::currentTime(); |
|
10 | QTime now = QTime::currentTime(); | |
11 | qsrand((uint)now.msec()); |
|
11 | qsrand((uint)now.msec()); | |
12 | setChartTitle("Three random line charts"); |
|
12 | setChartTitle("Three random line charts"); | |
13 |
|
13 | |||
14 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); |
|
14 | QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); | |
15 |
m_timer.setInterval( |
|
15 | m_timer.setInterval(1000); | |
16 |
|
16 | |||
17 | m_series0 = new QLineSeries(this); |
|
17 | m_series0 = new QLineSeries(this); | |
18 | QPen blue(Qt::blue); |
|
18 | QPen blue(Qt::blue); | |
19 | blue.setWidth(3); |
|
19 | blue.setWidth(3); | |
20 | m_series0->setPen(blue); |
|
20 | m_series0->setPen(blue); | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | m_series1 = new QSplineSeries(this); |
|
23 | m_series1 = new QSplineSeries(this); | |
24 |
QPen green(Qt:: |
|
24 | QPen green(Qt::red); | |
25 | green.setWidth(3); |
|
25 | green.setWidth(3); | |
26 | m_series1->setPen(green); |
|
26 | m_series1->setPen(green); | |
27 |
|
27 | |||
28 |
|
||||
29 | m_series0->add(m_x,m_y); |
|
28 | m_series0->add(m_x,m_y); | |
30 | m_series1->add(m_x,m_y); |
|
29 | m_series1->add(m_x,m_y); | |
31 |
|
30 | |||
32 |
setChartTitle("Simple EKG |
|
31 | setChartTitle("Simple EKG chart"); | |
33 | addSeries(m_series0); |
|
32 | addSeries(m_series0); | |
34 | addSeries(m_series1); |
|
33 | addSeries(m_series1); | |
35 | axisY()->setRange(-5,5); |
|
34 | axisY()->setRange(-5,5); | |
36 | axisX()->setRange(-9,1); |
|
35 | axisX()->setRange(-9,1); | |
37 | axisX()->setTicksCount(11); |
|
36 | axisX()->setTicksCount(11); | |
38 | m_timer.start(); |
|
37 | m_timer.start(); | |
39 | } |
|
38 | } | |
40 |
|
39 | |||
41 | ChartView::~ChartView() |
|
40 | ChartView::~ChartView() | |
42 | { |
|
41 | { | |
43 |
|
42 | |||
44 | } |
|
43 | } | |
45 |
|
44 | |||
46 | void ChartView::handleTimeout() |
|
45 | void ChartView::handleTimeout() | |
47 | { |
|
46 | { | |
48 | m_x+=m_step; |
|
47 | m_x+=m_step; | |
49 | m_y = qrand() % 5 - 2.5; |
|
48 | m_y = qrand() % 5 - 2.5; | |
50 | m_series0->add(m_x,m_y); |
|
49 | m_series0->add(m_x,m_y); | |
51 | m_series1->add(m_x,m_y); |
|
50 | m_series1->add(m_x,m_y); | |
52 | if(m_x>=10) |
|
51 | if(m_x>=10) | |
53 | { |
|
52 | { | |
54 | m_series0->remove(m_x-10); |
|
53 | m_series0->remove(m_x-10); | |
55 | m_series1->remove(m_x-10); |
|
54 | m_series1->remove(m_x-10); | |
56 | } |
|
55 | } | |
57 | scrollRight(); |
|
56 | scrollRight(); | |
58 | } |
|
57 | } |
@@ -1,51 +1,51 | |||||
1 | #include <QApplication> |
|
1 | #include <QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <QChartView> |
|
3 | #include <QChartView> | |
4 | #include <QLineSeries> |
|
4 | #include <QLineSeries> | |
5 | #include <cmath> |
|
5 | #include <cmath> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
8 |
|
8 | |||
9 | int main(int argc, char *argv[]) |
|
9 | int main(int argc, char *argv[]) | |
10 | { |
|
10 | { | |
11 | QApplication a(argc, argv); |
|
11 | QApplication a(argc, argv); | |
12 |
|
12 | |||
13 | //![1] |
|
13 | //![1] | |
14 | QLineSeries* series0 = new QLineSeries(); |
|
14 | QLineSeries* series0 = new QLineSeries(); | |
15 | QPen blue(Qt::blue); |
|
15 | QPen blue(Qt::blue); | |
16 | blue.setWidth(3); |
|
16 | blue.setWidth(3); | |
17 | series0->setPen(blue); |
|
17 | series0->setPen(blue); | |
18 |
|
18 | |||
19 | QLineSeries* series1 = new QLineSeries(); |
|
19 | QLineSeries* series1 = new QLineSeries(); | |
20 | QPen red(Qt::red); |
|
20 | QPen red(Qt::red); | |
21 | red.setWidth(3); |
|
21 | red.setWidth(3); | |
22 | series1->setPen(red); |
|
22 | series1->setPen(red); | |
23 | //![1] |
|
23 | //![1] | |
24 |
|
24 | |||
25 | //![2] |
|
25 | //![2] | |
26 | series0->add(0, 6); |
|
26 | series0->add(0, 6); | |
27 | series0->add(2, 4); |
|
27 | series0->add(2, 4); | |
28 | series0->add(3, 8); |
|
28 | series0->add(3, 8); | |
29 | series0->add(7, 4); |
|
29 | series0->add(7, 4); | |
30 | series0->add(10,5); |
|
30 | series0->add(10,5); | |
31 |
|
31 | |||
32 | *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10,2); |
|
32 | *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10,2); | |
33 | //![2] |
|
33 | //![2] | |
34 | //![3] |
|
34 | //![3] | |
35 | QMainWindow window; |
|
35 | QMainWindow window; | |
36 | QChartView* chartView = new QChartView(&window); |
|
36 | QChartView* chartView = new QChartView(&window); | |
37 |
|
37 | |||
38 |
chartView->setChartTitle(" |
|
38 | chartView->setChartTitle("Simple line chart"); | |
39 | chartView->setRenderHint(QPainter::Antialiasing); |
|
39 | chartView->setRenderHint(QPainter::Antialiasing); | |
40 |
|
40 | |||
41 | chartView->addSeries(series0); |
|
41 | chartView->addSeries(series0); | |
42 | chartView->addSeries(series1); |
|
42 | chartView->addSeries(series1); | |
43 | //![3] |
|
43 | //![3] | |
44 | //![4] |
|
44 | //![4] | |
45 | window.setCentralWidget(chartView); |
|
45 | window.setCentralWidget(chartView); | |
46 | window.resize(400, 300); |
|
46 | window.resize(400, 300); | |
47 | window.show(); |
|
47 | window.show(); | |
48 | //![4] |
|
48 | //![4] | |
49 |
|
49 | |||
50 | return a.exec(); |
|
50 | return a.exec(); | |
51 | } |
|
51 | } |
General Comments 0
You need to be logged in to leave comments.
Login now