@@ -0,0 +1,37 | |||||
|
1 | #include <QtGui/QApplication> | |||
|
2 | #include <QMainWindow> | |||
|
3 | #include <cmath> | |||
|
4 | #include <qchartglobal.h> | |||
|
5 | #include <qchartwidget.h> | |||
|
6 | #include <qscatterseries.h> | |||
|
7 | ||||
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
9 | ||||
|
10 | int main(int argc, char *argv[]) | |||
|
11 | { | |||
|
12 | QApplication a(argc, argv); | |||
|
13 | ||||
|
14 | // Create widget and scatter series | |||
|
15 | QChartWidget chartWidget; | |||
|
16 | QScatterSeries *scatter = | |||
|
17 | qobject_cast<QScatterSeries *>(chartWidget.createSeries(QChartSeries::SeriesTypeScatter)); | |||
|
18 | Q_ASSERT(scatter); | |||
|
19 | ||||
|
20 | // Add test data to the series | |||
|
21 | QList<qreal> x; | |||
|
22 | QList<qreal> y; | |||
|
23 | for (qreal i(0.0); i < 20; i += 0.5) { | |||
|
24 | // Linear data with random component | |||
|
25 | x.append(i + ((qreal)(rand() % 100)) / 100 ); | |||
|
26 | y.append(i + ((qreal)(rand() % 100)) / 100 ); | |||
|
27 | } | |||
|
28 | scatter->setData(x, y); | |||
|
29 | ||||
|
30 | // Use the chart widget as the central widget | |||
|
31 | QMainWindow w; | |||
|
32 | w.resize(640, 480); | |||
|
33 | w.setCentralWidget(&chartWidget); | |||
|
34 | w.show(); | |||
|
35 | ||||
|
36 | return a.exec(); | |||
|
37 | } |
General Comments 0
You need to be logged in to leave comments.
Login now