main.cpp
55 lines
| 1.3 KiB
| text/x-c
|
CppLexer
|
r12 | #include <QApplication> | ||
#include <QMainWindow> | ||||
|
r58 | #include <qchartview.h> | ||
|
r21 | #include <qxychartseries.h> | ||
|
r12 | #include <qchart.h> | ||
#include <cmath> | ||||
|
r30 | QTCOMMERCIALCHART_USE_NAMESPACE | ||
|
r12 | |||
#define PI 3.14159265358979 | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
QMainWindow window; | ||||
|
r21 | QXYChartSeries* series0 = QXYChartSeries::create(); | ||
|
r12 | series0->setColor(Qt::blue); | ||
|
r21 | QXYChartSeries* series1 = QXYChartSeries::create(); | ||
|
r12 | series1->setColor(Qt::red); | ||
|
r21 | QXYChartSeries* series2 = QXYChartSeries::create(); | ||
|
r12 | series2->setColor(Qt::gray); | ||
|
r21 | QXYChartSeries* series3 = QXYChartSeries::create(); | ||
|
r12 | series3->setColor(Qt::green); | ||
int numPoints = 100; | ||||
for (int x = 0; x < numPoints; ++x) { | ||||
series0->add(x,0); | ||||
|
r14 | series1->add(x, abs(sin(PI/50*x)*100)); | ||
series2->add(x, abs(cos(PI/50*x)*100)); | ||||
|
r12 | series3->add(x,100); | ||
} | ||||
|
r21 | QList<QXYChartSeries*> dataset; | ||
|
r12 | |||
|
r21 | //qDebug()<<"Series 1:" << *series1; | ||
//qDebug()<<"Series 2:" << *series2; | ||||
|
r12 | |||
dataset << series0; | ||||
dataset << series1; | ||||
dataset << series2; | ||||
dataset << series3; | ||||
|
r58 | QChartView* chartView = new QChartView(&window); | ||
chartView->addSeries(series1); | ||||
chartView->addSeries(series2); | ||||
|
r12 | |||
|
r58 | window.setCentralWidget(chartView); | ||
|
r12 | window.resize(400, 300); | ||
window.show(); | ||||
return a.exec(); | ||||
} | ||||