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