|
@@
-1,77
+1,83
|
|
1
|
#include <QtGui/QApplication>
|
|
1
|
#include <QtGui/QApplication>
|
|
2
|
#include <QMainWindow>
|
|
2
|
#include <QMainWindow>
|
|
3
|
#include <qchartglobal.h>
|
|
3
|
#include <qchartglobal.h>
|
|
4
|
#include <qchartview.h>
|
|
4
|
#include <qchartview.h>
|
|
5
|
#include <qlinechartseries.h>
|
|
5
|
#include <qlinechartseries.h>
|
|
6
|
#include <qscatterseries.h>
|
|
6
|
#include <qscatterseries.h>
|
|
7
|
#include <qbarseries.h>
|
|
7
|
#include <qbarseries.h>
|
|
8
|
#include <qbarset.h>
|
|
8
|
#include <qbarset.h>
|
|
9
|
#include <qbarcategory.h>
|
|
9
|
#include <qbarcategory.h>
|
|
10
|
#include <qpieseries.h>
|
|
10
|
#include <qpieseries.h>
|
|
11
|
|
|
11
|
|
|
12
|
QTCOMMERCIALCHART_USE_NAMESPACE
|
|
12
|
QTCOMMERCIALCHART_USE_NAMESPACE
|
|
13
|
|
|
13
|
|
|
14
|
int main(int argc, char *argv[])
|
|
14
|
int main(int argc, char *argv[])
|
|
15
|
{
|
|
15
|
{
|
|
16
|
QApplication a(argc, argv);
|
|
16
|
QApplication a(argc, argv);
|
|
17
|
|
|
17
|
|
|
18
|
//! [1]
|
|
18
|
//! [1]
|
|
19
|
// Create chart view
|
|
19
|
// Create chart view
|
|
20
|
QChartView *chartView = new QChartView();
|
|
20
|
QChartView *chartView = new QChartView();
|
|
21
|
chartView->setRenderHint(QPainter::Antialiasing);
|
|
21
|
chartView->setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
22
|
chartView->setChartTitle("Simple Line Chart");
|
|
22
|
// Add series to the chart
|
|
23
|
// Add series to the chart
|
|
23
|
QLineChartSeries *line = new QLineChartSeries();
|
|
24
|
QLineChartSeries *line = new QLineChartSeries();
|
|
24
|
line->add(0.0, 0.8);
|
|
25
|
line->add(0.0, 0.8);
|
|
25
|
line->add(1.1, 1.1);
|
|
26
|
line->add(1.1, 1.1);
|
|
26
|
line->add(2.0, 2.5);
|
|
27
|
line->add(2.0, 2.5);
|
|
27
|
chartView->addSeries(line);
|
|
28
|
chartView->addSeries(line);
|
|
28
|
//! [1]
|
|
29
|
//! [1]
|
|
29
|
|
|
30
|
|
|
|
|
|
31
|
chartView->setChartTitle("\'Scietific\' theme");
|
|
30
|
//! [2]
|
|
32
|
//! [2]
|
|
31
|
// Change theme
|
|
33
|
// Change theme
|
|
32
|
chartView->setChartTheme(QChart::ChartThemeScientific);
|
|
34
|
chartView->setChartTheme(QChart::ChartThemeScientific);
|
|
33
|
//! [2]
|
|
35
|
//! [2]
|
|
34
|
|
|
36
|
|
|
|
|
|
37
|
chartView->setChartTitle("Simple Pie Chart");
|
|
35
|
//! [3]
|
|
38
|
//! [3]
|
|
36
|
// Add pie series
|
|
39
|
// Add pie series
|
|
37
|
// ...
|
|
40
|
// ...
|
|
38
|
QPieSeries *pie = new QPieSeries();
|
|
41
|
QPieSeries *pie = new QPieSeries();
|
|
39
|
pie->add(3.4, "slice1");
|
|
42
|
pie->add(3.4, "slice1");
|
|
40
|
pie->add(6.7, "slice2");
|
|
43
|
pie->add(6.7, "slice2");
|
|
41
|
chartView->addSeries(pie);
|
|
44
|
chartView->addSeries(pie);
|
|
42
|
//! [3]
|
|
45
|
//! [3]
|
|
43
|
|
|
46
|
|
|
|
|
|
47
|
chartView->setChartTitle("Simple Scatter Chart");
|
|
44
|
//! [4]
|
|
48
|
//! [4]
|
|
45
|
// Add scatter series
|
|
49
|
// Add scatter series
|
|
46
|
// ...
|
|
50
|
// ...
|
|
47
|
QScatterSeries *scatter = new QScatterSeries();
|
|
51
|
QScatterSeries *scatter = new QScatterSeries();
|
|
48
|
for (qreal x(0); x < 100; x += 0.5) {
|
|
52
|
for (qreal x(0); x < 100; x += 0.5) {
|
|
49
|
qreal y = rand() % 100;
|
|
53
|
qreal y = rand() % 100;
|
|
50
|
*(scatter) << QPointF(x, y);
|
|
54
|
*(scatter) << QPointF(x, y);
|
|
51
|
}
|
|
55
|
}
|
|
52
|
chartView->addSeries(scatter);
|
|
56
|
chartView->addSeries(scatter);
|
|
53
|
//! [4]
|
|
57
|
//! [4]
|
|
54
|
|
|
58
|
|
|
|
|
|
59
|
chartView->setChartTitle("Simple Bar Chart");
|
|
55
|
//! [5]
|
|
60
|
//! [5]
|
|
56
|
// ...
|
|
61
|
// ...
|
|
57
|
// Add bar series
|
|
62
|
// Add bar series
|
|
58
|
QBarCategory *barCategory = new QBarCategory();
|
|
63
|
QBarCategory *barCategory = new QBarCategory();
|
|
59
|
*barCategory << "Jan"
|
|
64
|
*barCategory << "Jan"
|
|
60
|
<< "Feb"
|
|
65
|
<< "Feb"
|
|
61
|
<< "Mar";
|
|
66
|
<< "Mar";
|
|
62
|
QBarSeries *bar = new QBarSeries(barCategory);
|
|
67
|
QBarSeries *bar = new QBarSeries(barCategory);
|
|
63
|
QBarSet *barSet = new QBarSet("Sales");
|
|
68
|
QBarSet *barSet = new QBarSet("Sales");
|
|
64
|
*barSet << 123.2
|
|
69
|
*barSet << 123.2
|
|
65
|
<< 301.3
|
|
70
|
<< 301.3
|
|
66
|
<< 285.8;
|
|
71
|
<< 285.8;
|
|
67
|
bar->addBarSet(barSet);
|
|
72
|
bar->addBarSet(barSet);
|
|
68
|
chartView->addSeries(bar);
|
|
73
|
chartView->addSeries(bar);
|
|
69
|
//! [5]
|
|
74
|
//! [5]
|
|
70
|
|
|
75
|
|
|
71
|
QMainWindow w;
|
|
76
|
QMainWindow w;
|
|
72
|
w.resize(380, 250);
|
|
77
|
w.resize(400, 300);
|
|
73
|
w.setCentralWidget(chartView);
|
|
78
|
w.setCentralWidget(chartView);
|
|
|
|
|
79
|
w.setWindowFlags(Qt::FramelessWindowHint);
|
|
74
|
w.show();
|
|
80
|
w.show();
|
|
75
|
|
|
81
|
|
|
76
|
return a.exec();
|
|
82
|
return a.exec();
|
|
77
|
}
|
|
83
|
}
|