main.cpp
67 lines
| 1.7 KiB
| text/x-c
|
CppLexer
Tero Ahola
|
r123 | #include <QtGui/QApplication> | ||
#include <QMainWindow> | ||||
#include <qchartglobal.h> | ||||
Michal Klocek
|
r136 | #include <qchartview.h> | ||
Tero Ahola
|
r123 | #include <qscatterseries.h> | ||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
Tero Ahola
|
r300 | //! [1] | ||
// Create chart view | ||||
Tero Ahola
|
r260 | QChartView *chartView = new QChartView(); | ||
Tero Ahola
|
r312 | chartView->setChartTheme(QChart::ChartThemeIcy); | ||
Tero Ahola
|
r182 | |||
Tero Ahola
|
r195 | // Add scatter series with simple test data | ||
Tero Ahola
|
r180 | QScatterSeries *scatter = new QScatterSeries(); | ||
Tero Ahola
|
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.5, 5.0); | ||||
Tero Ahola
|
r260 | // Chart takes ownership | ||
chartView->addSeries(scatter); | ||||
Tero Ahola
|
r278 | //! [1] | ||
Tero Ahola
|
r123 | |||
Tero Ahola
|
r300 | // Add some more data | ||
//! [2] | ||||
scatter->addData(QPointF(2.0, 5.5)); | ||||
//! [2] | ||||
// And more | ||||
//! [3] | ||||
*scatter << QPointF(2.0, 5.5); | ||||
//! [3] | ||||
// Add another scatter series (re-use the previous pointer) | ||||
Tero Ahola
|
r195 | // - more data with random component | ||
Tero Ahola
|
r300 | scatter = new QScatterSeries(); | ||
Tero Ahola
|
r261 | for (qreal i(0.0); i < 20; i += 0.15) { | ||
Tero Ahola
|
r300 | (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0, | ||
Tero Ahola
|
r195 | i + (qreal)(rand() % 100) / 100.0); | ||
} | ||||
Tero Ahola
|
r300 | //! [4] | ||
Tero Ahola
|
r261 | QBrush brush(QColor(255, 0, 0, 100), Qt::SolidPattern); | ||
Tero Ahola
|
r300 | scatter->setMarkerBrush(brush); | ||
//! [4] | ||||
//! [5] | ||||
Tero Ahola
|
r261 | QPen pen(QColor(0, 255, 0, 80), 3); | ||
Tero Ahola
|
r300 | scatter->setMarkerPen(pen); | ||
//! [5] | ||||
//! [6] | ||||
scatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | ||||
//! [6] | ||||
chartView->addSeries(scatter); | ||||
Tero Ahola
|
r123 | |||
// Use the chart widget as the central widget | ||||
QMainWindow w; | ||||
w.resize(640, 480); | ||||
Tero Ahola
|
r260 | w.setCentralWidget(chartView); | ||
Tero Ahola
|
r123 | w.show(); | ||
return a.exec(); | ||||
} | ||||