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