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