main.cpp
46 lines
| 1.0 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r12 | #include <QApplication> | ||
#include <QMainWindow> | ||||
Michal Klocek
|
r58 | #include <qchartview.h> | ||
Michal Klocek
|
r145 | #include <qlinechartseries.h> | ||
Michal Klocek
|
r12 | #include <qchart.h> | ||
#include <cmath> | ||||
Tero Ahola
|
r30 | QTCOMMERCIALCHART_USE_NAMESPACE | ||
Michal Klocek
|
r12 | |||
#define PI 3.14159265358979 | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
QMainWindow window; | ||||
Michal Klocek
|
r156 | QLineChartSeries* series0 = new QLineChartSeries(); | ||
Michal Klocek
|
r85 | QPen blue(Qt::blue); | ||
blue.setWidth(3); | ||||
series0->setPen(blue); | ||||
Michal Klocek
|
r156 | QLineChartSeries* series1 = new QLineChartSeries(); | ||
Michal Klocek
|
r85 | QPen red(Qt::red); | ||
red.setWidth(3); | ||||
series1->setPen(red); | ||||
Michal Klocek
|
r12 | |||
int numPoints = 100; | ||||
Michal Klocek
|
r67 | for (int x = 0; x <= numPoints; ++x) { | ||
Michal Klocek
|
r131 | series0->add(x, fabs(sin(PI/50*x)*100)); | ||
series1->add(x, fabs(cos(PI/50*x)*100)); | ||||
Michal Klocek
|
r67 | } | ||
Michal Klocek
|
r12 | |||
Michal Klocek
|
r58 | QChartView* chartView = new QChartView(&window); | ||
Michal Klocek
|
r131 | |||
Michal Klocek
|
r85 | chartView->setRenderHint(QPainter::Antialiasing); | ||
Michal Klocek
|
r192 | chartView->setChartTitle("Basic line chart example"); | ||
Michal Klocek
|
r67 | chartView->addSeries(series0); | ||
Michal Klocek
|
r58 | chartView->addSeries(series1); | ||
Michal Klocek
|
r12 | |||
Michal Klocek
|
r58 | window.setCentralWidget(chartView); | ||
Michal Klocek
|
r12 | window.resize(400, 300); | ||
window.show(); | ||||
return a.exec(); | ||||
} | ||||