main.cpp
78 lines
| 2.0 KiB
| text/x-c
|
CppLexer
|
r176 | #include <QApplication> | ||
#include <QMainWindow> | ||||
#include <qchartview.h> | ||||
|
r349 | #include <qlineseries.h> | ||
|
r176 | #include <qchart.h> | ||
#include <qchartaxis.h> | ||||
|
r445 | #include <qchartaxiscategories.h> | ||
|
r176 | #include <cmath> | ||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
#define PI 3.14159265358979 | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
QMainWindow window; | ||||
|
r349 | QLineSeries* series0 = new QLineSeries(); | ||
|
r176 | QPen blue(Qt::blue); | ||
blue.setWidth(3); | ||||
series0->setPen(blue); | ||||
|
r349 | QLineSeries* series1 = new QLineSeries(); | ||
|
r176 | QPen red(Qt::red); | ||
red.setWidth(3); | ||||
series1->setPen(red); | ||||
int numPoints = 100; | ||||
for (int x = 0; x <= numPoints; ++x) { | ||||
series0->add(x, fabs(sin(PI/50*x)*100)); | ||||
series1->add(x, fabs(cos(PI/50*x)*100)); | ||||
} | ||||
QChartView* chartView = new QChartView(&window); | ||||
chartView->setRenderHint(QPainter::Antialiasing); | ||||
|
r192 | chartView->setChartTitle("This is custom axis chart example"); | ||
|
r176 | chartView->addSeries(series0); | ||
chartView->addSeries(series1); | ||||
|
r188 | |||
QLinearGradient backgroundGradient; | ||||
backgroundGradient.setColorAt(0.0, Qt::white); | ||||
backgroundGradient.setColorAt(1.0, QRgb(0xffff80)); | ||||
backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | ||||
chartView->setChartBackgroundBrush(backgroundGradient); | ||||
|
r176 | |||
|
r225 | QChartAxis* axisX = chartView->axisX(); | ||
axisX->setLabelsAngle(45); | ||||
|
r535 | axisX->setGridLinePen(Qt::DashLine); | ||
|
r445 | |||
|
r502 | QChartAxisCategories* categoriesX = axisX->categories(); | ||
|
r501 | categoriesX->insert(0,"low"); | ||
categoriesX->insert(50,"medium"); | ||||
categoriesX->insert(100,"High"); | ||||
|
r445 | |||
|
r400 | axisX->setMin(-10); | ||
|
r450 | axisX->setMax(2200); | ||
|
r176 | |||
|
r225 | QChartAxis* axisY = chartView->axisY(); | ||
axisY->setLabelsAngle(45); | ||||
axisY->setShadesBrush(Qt::yellow); | ||||
|
r445 | |||
|
r502 | QChartAxisCategories* categoriesY = axisY->categories(); | ||
|
r501 | categoriesY->insert(0,"low"); | ||
categoriesY->insert(50,"medium"); | ||||
categoriesY->insert(100,"High"); | ||||
|
r445 | |||
|
r400 | axisY->setMin(-10); | ||
axisY->setMax(200); | ||||
|
r176 | |||
window.setCentralWidget(chartView); | ||||
window.resize(400, 300); | ||||
window.show(); | ||||
return a.exec(); | ||||
} | ||||