diff --git a/examples/ekgchart/chartview.cpp b/examples/ekgchart/chartview.cpp new file mode 100644 index 0000000..1ef6175 --- /dev/null +++ b/examples/ekgchart/chartview.cpp @@ -0,0 +1,53 @@ +#include "chartview.h" +#include +#include + +ChartView::ChartView(QWidget* parent):QChartView(parent), +m_step(1), +m_x(0), +m_y(1) +{ + QTime now = QTime::currentTime(); + qsrand((uint)now.msec()); + setChartTitle("Three random line charts"); + + QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout())); + m_timer.setInterval(1000); + + m_series0 = new QLineSeries(this); + QPen blue(Qt::blue); + blue.setWidth(3); + m_series0->setPen(blue); + + + m_series1 = new QSplineSeries(this); + QPen green(Qt::green); + green.setWidth(3); + m_series1->setPen(green); + + + m_series0->add(m_x,m_y); + m_series1->add(m_x,m_y); + + setChartTitle("Simple EKG exmaple"); + addSeries(m_series0); + addSeries(m_series1); + axisY()->setRange(-5,5); + axisX()->setRange(-9,1); + axisX()->setTicksCount(11); + m_timer.start(); +} + +ChartView::~ChartView() +{ + +} + +void ChartView::handleTimeout() +{ + m_x+=m_step; + m_y = qrand() % 5 - 2.5; + m_series0->add(m_x,m_y); + m_series1->add(m_x,m_y); + scrollRight(); +} diff --git a/examples/ekgchart/chartview.h b/examples/ekgchart/chartview.h new file mode 100644 index 0000000..784f5d7 --- /dev/null +++ b/examples/ekgchart/chartview.h @@ -0,0 +1,37 @@ +#ifndef CHARTVIEW_H_ +#define CHARTVIEW_H_ + +#include +#include + + +QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QSplineSeries; +class QLineSeries; +QTCOMMERCIALCHART_END_NAMESPACE + +QTCOMMERCIALCHART_USE_NAMESPACE + +//![1] +class ChartView: public QChartView +{ + Q_OBJECT +public: + ChartView(QWidget* parent=0); + virtual ~ChartView(); + +public slots: + void handleTimeout(); + +private: + QTimer m_timer; + QLineSeries* m_series0; + QSplineSeries* m_series1; + QStringList m_titles; + qreal m_step; + qreal m_x; + qreal m_y; +}; +//![1] + +#endif /* CHARTVIEW_H_ */ diff --git a/examples/ekgchart/ekgchart.pro b/examples/ekgchart/ekgchart.pro new file mode 100644 index 0000000..395db3d --- /dev/null +++ b/examples/ekgchart/ekgchart.pro @@ -0,0 +1,6 @@ +!include( ../examples.pri ) { + error( "Couldn't find the examples.pri file!" ) +} +TARGET = ekgchart +HEADERS += chartview.h +SOURCES += main.cpp chartview.cpp \ No newline at end of file diff --git a/examples/ekgchart/main.cpp b/examples/ekgchart/main.cpp new file mode 100644 index 0000000..ba65e4d --- /dev/null +++ b/examples/ekgchart/main.cpp @@ -0,0 +1,16 @@ +#include "chartview.h" +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QMainWindow window; + ChartView chartView(&window); + chartView.setRenderHint(QPainter::Antialiasing); + chartView.setAnimationOptions(QChart::AllAnimations); + window.setCentralWidget(&chartView); + window.resize(400, 300); + window.show(); + return a.exec(); +} diff --git a/examples/examples.pro b/examples/examples.pro index 5dbbc0c..df146a0 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -19,4 +19,5 @@ SUBDIRS += linechart \ areachart \ stackedbarchartdrilldown \ customcolors \ - tablemodelchart + tablemodelchart \ + ekgchart