main.cpp
57 lines
| 1.6 KiB
| text/x-c
|
CppLexer
|
r123 | #include <QtGui/QApplication> | ||
#include <QMainWindow> | ||||
#include <cmath> | ||||
#include <qchartglobal.h> | ||||
|
r136 | #include <qchartview.h> | ||
|
r123 | #include <qscatterseries.h> | ||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
|
r182 | // Create chart widget | ||
|
r136 | QChartView *chartWidget = new QChartView(); | ||
|
r182 | |||
|
r195 | // Add scatter series with simple test data | ||
|
r180 | QScatterSeries *scatter = new QScatterSeries(); | ||
|
r195 | *scatter << QPointF(0.5, 5.0) | ||
<< QPointF(1.0, 4.5) | ||||
<< QPointF(1.0, 5.5) | ||||
<< QPointF(1.5, 5.0) | ||||
<< QPointF(2.0, 4.5) | ||||
<< QPointF(2.0, 5.5) | ||||
<< QPointF(2.5, 5.0); | ||||
|
r182 | chartWidget->addSeries(scatter); | ||
|
r123 | |||
|
r195 | // Add another scatter series | ||
// - more data with random component | ||||
|
r182 | QScatterSeries *scatter2 = new QScatterSeries(); | ||
|
r195 | for (qreal i(0.0); i < 20; i += 0.05) { | ||
|
r182 | (*scatter2) << QPointF(i + (qreal)(rand() % 100) / 100.0, | ||
|
r195 | i + (qreal)(rand() % 100) / 100.0); | ||
} | ||||
|
r182 | chartWidget->addSeries(scatter2); | ||
|
r195 | // Custom pen and brush (not those defined by the chart theme) | ||
// - uses opaque color | ||||
QColor color("#2685BF"); | ||||
color.setAlpha(80); | ||||
QBrush brush(Qt::SolidPattern); | ||||
brush.setColor(color); | ||||
scatter2->setMarkerBrush(brush); | ||||
QPen pen; | ||||
pen.setColor(color); | ||||
pen.setWidth(2); | ||||
scatter2->setMarkerPen(pen); | ||||
// use a rectangle as the marker shape | ||||
scatter2->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | ||||
|
r123 | |||
// Use the chart widget as the central widget | ||||
QMainWindow w; | ||||
w.resize(640, 480); | ||||
|
r129 | w.setCentralWidget(chartWidget); | ||
|
r123 | w.show(); | ||
return a.exec(); | ||||
} | ||||