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