main.cpp
67 lines
| 1.9 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r176 | #include <QApplication> | ||
#include <QMainWindow> | ||||
#include <qchartview.h> | ||||
Michal Klocek
|
r349 | #include <qlineseries.h> | ||
Michal Klocek
|
r176 | #include <qchart.h> | ||
#include <qchartaxis.h> | ||||
Michal Klocek
|
r445 | #include <qchartaxiscategories.h> | ||
Michal Klocek
|
r176 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
QMainWindow window; | ||||
Michal Klocek
|
r349 | QLineSeries* series0 = new QLineSeries(); | ||
Michal Klocek
|
r176 | QPen blue(Qt::blue); | ||
blue.setWidth(3); | ||||
series0->setPen(blue); | ||||
Michal Klocek
|
r706 | *series0 << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); | ||
Michal Klocek
|
r176 | |||
QChartView* chartView = new QChartView(&window); | ||||
chartView->setRenderHint(QPainter::Antialiasing); | ||||
Michal Klocek
|
r706 | chartView->setChartTitle("Simple axis example"); | ||
Michal Klocek
|
r176 | chartView->addSeries(series0); | ||
Michal Klocek
|
r188 | |||
QLinearGradient backgroundGradient; | ||||
backgroundGradient.setColorAt(0.0, Qt::white); | ||||
Michal Klocek
|
r572 | backgroundGradient.setColorAt(1.0, Qt::white); | ||
Michal Klocek
|
r188 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | ||
chartView->setChartBackgroundBrush(backgroundGradient); | ||||
Michal Klocek
|
r176 | |||
Michal Klocek
|
r225 | QChartAxis* axisX = chartView->axisX(); | ||
Michal Klocek
|
r706 | axisX->setRange(0,10); | ||
axisX->setTicksCount(4); | ||||
axisX->setGridLineVisible(true); | ||||
axisX->setShadesVisible(false); | ||||
Michal Klocek
|
r176 | |||
Michal Klocek
|
r225 | QChartAxis* axisY = chartView->axisY(); | ||
Michal Klocek
|
r706 | axisY->setRange(0,10); | ||
Michal Klocek
|
r225 | axisY->setLabelsAngle(45); | ||
Michal Klocek
|
r706 | axisY->setTicksCount(4); | ||
axisY->setShadesPen(Qt::NoPen); | ||||
axisY->setShadesOpacity(0.5); | ||||
axisY->setShadesBrush(Qt::blue); | ||||
Michal Klocek
|
r572 | axisY->setGridLineVisible(false); | ||
Michal Klocek
|
r706 | axisY->setShadesVisible(true); | ||
Michal Klocek
|
r445 | |||
Michal Klocek
|
r706 | QChartAxisCategories* categoriesX = axisX->categories(); | ||
categoriesX->insert(1,"low"); | ||||
categoriesX->insert(5,"optimal"); | ||||
categoriesX->insert(10,"high"); | ||||
Michal Klocek
|
r445 | |||
Michal Klocek
|
r706 | QChartAxisCategories* categoriesY = axisY->categories(); | ||
categoriesY->insert(1,"slow"); | ||||
categoriesY->insert(5,"med"); | ||||
categoriesY->insert(10,"fast"); | ||||
Michal Klocek
|
r176 | |||
window.setCentralWidget(chartView); | ||||
window.resize(400, 300); | ||||
window.show(); | ||||
return a.exec(); | ||||
} | ||||