@@ -21,12 +21,15 | |||
|
21 | 21 | #include "chart.h" |
|
22 | 22 | #include <QAbstractAxis> |
|
23 | 23 | #include <QSplineSeries> |
|
24 | #include <QValuesAxis> | |
|
24 | 25 | #include <QTime> |
|
26 | #include <QDebug> | |
|
25 | 27 | |
|
26 | 28 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
27 | 29 | :QChart(parent, wFlags), |
|
28 |
m_step( |
|
|
29 | m_x(0), | |
|
30 | m_step(0), | |
|
31 | m_axis(new QValuesAxis), | |
|
32 | m_x(5), | |
|
30 | 33 | m_y(1) |
|
31 | 34 | { |
|
32 | 35 | qsrand((uint) QTime::currentTime().msec()); |
@@ -42,10 +45,10 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |||
|
42 | 45 | |
|
43 | 46 | addSeries(m_series); |
|
44 | 47 | createDefaultAxes(); |
|
45 | ||
|
46 |
axis |
|
|
47 |
axisX()->setRange( |
|
|
48 | //TODO:axisX()->setTicksCount(11); | |
|
48 | setAxisX(m_axis,m_series); | |
|
49 | m_axis->setTicksCount(5); | |
|
50 | axisX()->setRange(0, 10); | |
|
51 | axisY()->setRange(-5, 10); | |
|
49 | 52 | |
|
50 | 53 | m_timer.start(); |
|
51 | 54 | } |
@@ -57,9 +60,11 Chart::~Chart() | |||
|
57 | 60 | |
|
58 | 61 | void Chart::handleTimeout() |
|
59 | 62 | { |
|
60 | m_x += m_step; | |
|
63 | qreal x = plotArea().width()/m_axis->ticksCount(); | |
|
64 | qreal y =(m_axis->max() - m_axis->min())/m_axis->ticksCount(); | |
|
65 | m_x += y; | |
|
61 | 66 | m_y = qrand() % 5 - 2.5; |
|
62 | 67 | m_series->append(m_x, m_y); |
|
63 |
scroll( |
|
|
68 | scroll(x,0); | |
|
64 | 69 | if(m_x==100) m_timer.stop(); |
|
65 | 70 | } |
@@ -26,6 +26,7 | |||
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | class QSplineSeries; |
|
29 | class QValuesAxis; | |
|
29 | 30 | QTCOMMERCIALCHART_END_NAMESPACE |
|
30 | 31 | |
|
31 | 32 | QTCOMMERCIALCHART_USE_NAMESPACE |
@@ -45,6 +46,7 private: | |||
|
45 | 46 | QTimer m_timer; |
|
46 | 47 | QSplineSeries* m_series; |
|
47 | 48 | QStringList m_titles; |
|
49 | QValuesAxis* m_axis; | |
|
48 | 50 | qreal m_step; |
|
49 | 51 | qreal m_x; |
|
50 | 52 | qreal m_y; |
@@ -451,7 +451,7 void ChartPresenter::setMarginsMinimum(const QRectF& margins) | |||
|
451 | 451 | |
|
452 | 452 | QRectF ChartPresenter::margins() const |
|
453 | 453 | { |
|
454 |
return |
|
|
454 | return m_layout->margins(); | |
|
455 | 455 | } |
|
456 | 456 | |
|
457 | 457 | QLegend* ChartPresenter::legend() |
General Comments 0
You need to be logged in to leave comments.
Login now