main.cpp
67 lines
| 1.9 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 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
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); | ||||
|
r706 | *series0 << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5); | ||
|
r176 | |||
QChartView* chartView = new QChartView(&window); | ||||
chartView->setRenderHint(QPainter::Antialiasing); | ||||
|
r706 | chartView->setChartTitle("Simple axis example"); | ||
|
r176 | chartView->addSeries(series0); | ||
|
r188 | |||
QLinearGradient backgroundGradient; | ||||
backgroundGradient.setColorAt(0.0, Qt::white); | ||||
|
r572 | backgroundGradient.setColorAt(1.0, Qt::white); | ||
|
r188 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | ||
chartView->setChartBackgroundBrush(backgroundGradient); | ||||
|
r176 | |||
|
r225 | QChartAxis* axisX = chartView->axisX(); | ||
|
r706 | axisX->setRange(0,10); | ||
axisX->setTicksCount(4); | ||||
axisX->setGridLineVisible(true); | ||||
axisX->setShadesVisible(false); | ||||
|
r176 | |||
|
r225 | QChartAxis* axisY = chartView->axisY(); | ||
|
r706 | axisY->setRange(0,10); | ||
|
r225 | axisY->setLabelsAngle(45); | ||
|
r706 | axisY->setTicksCount(4); | ||
axisY->setShadesPen(Qt::NoPen); | ||||
axisY->setShadesOpacity(0.5); | ||||
axisY->setShadesBrush(Qt::blue); | ||||
|
r572 | axisY->setGridLineVisible(false); | ||
|
r706 | axisY->setShadesVisible(true); | ||
|
r445 | |||
|
r706 | QChartAxisCategories* categoriesX = axisX->categories(); | ||
categoriesX->insert(1,"low"); | ||||
categoriesX->insert(5,"optimal"); | ||||
categoriesX->insert(10,"high"); | ||||
|
r445 | |||
|
r706 | QChartAxisCategories* categoriesY = axisY->categories(); | ||
categoriesY->insert(1,"slow"); | ||||
categoriesY->insert(5,"med"); | ||||
categoriesY->insert(10,"fast"); | ||||
|
r176 | |||
window.setCentralWidget(chartView); | ||||
window.resize(400, 300); | ||||
window.show(); | ||||
return a.exec(); | ||||
} | ||||