##// END OF EJS Templates
Add data source to donutbreakdown
Jani Honkonen -
r1952:e4c30d13e9db
parent child
Show More
@@ -1,74 +1,78
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #include <QApplication>
20 #include <QApplication>
21 #include <QMainWindow>
21 #include <QMainWindow>
22 #include <QStatusBar>
22 #include <QChartView>
23 #include <QChartView>
23 #include "donutbreakdownchart.h"
24 #include "donutbreakdownchart.h"
24
25
25 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
26
27
27 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
28 {
29 {
29 QApplication a(argc, argv);
30 QApplication a(argc, argv);
30
31
31 //![1]
32 //![1]
32 // Data from http://www.stat.fi/til/ekul/2010/ekul_2010_2011-12-13_tie_001_en.html
33
34 QPieSeries *series1 = new QPieSeries();
33 QPieSeries *series1 = new QPieSeries();
35 series1->setName("Fossil fuels");
34 series1->setName("Fossil fuels");
36 series1->append("Oil", 353295);
35 series1->append("Oil", 353295);
37 series1->append("Coal", 188500);
36 series1->append("Coal", 188500);
38 series1->append("Natural gas", 148680);
37 series1->append("Natural gas", 148680);
39 series1->append("Peat", 94545);
38 series1->append("Peat", 94545);
40
39
41 QPieSeries *series2 = new QPieSeries();
40 QPieSeries *series2 = new QPieSeries();
42 series2->setName("Renewables");
41 series2->setName("Renewables");
43 series2->append("Wood fuels", 319663);
42 series2->append("Wood fuels", 319663);
44 series2->append("Hydro power", 45875);
43 series2->append("Hydro power", 45875);
45 series2->append("Wind power", 1060);
44 series2->append("Wind power", 1060);
46
45
47 QPieSeries *series3 = new QPieSeries();
46 QPieSeries *series3 = new QPieSeries();
48 series3->setName("Others");
47 series3->setName("Others");
49 series3->append("Nuclear energy", 238789);
48 series3->append("Nuclear energy", 238789);
50 series3->append("Import energy", 37802);
49 series3->append("Import energy", 37802);
51 series3->append("Other", 32441);
50 series3->append("Other", 32441);
52 //![1]
51 //![1]
53
52
54 //![2]
53 //![2]
55 DonutBreakdownChart *donutBreakdown = new DonutBreakdownChart();
54 DonutBreakdownChart *donutBreakdown = new DonutBreakdownChart();
56 donutBreakdown->setAnimationOptions(QChart::AllAnimations);
55 donutBreakdown->setAnimationOptions(QChart::AllAnimations);
57 donutBreakdown->setTitle("Total consumption of energy in Finland 2010");
56 donutBreakdown->setTitle("Total consumption of energy in Finland 2010");
58 donutBreakdown->legend()->setVisible(false);
57 donutBreakdown->legend()->setVisible(false);
59 donutBreakdown->addBreakdownSeries(series1, Qt::red);
58 donutBreakdown->addBreakdownSeries(series1, Qt::red);
60 donutBreakdown->addBreakdownSeries(series2, Qt::darkGreen);
59 donutBreakdown->addBreakdownSeries(series2, Qt::darkGreen);
61 donutBreakdown->addBreakdownSeries(series3, Qt::darkBlue);
60 donutBreakdown->addBreakdownSeries(series3, Qt::darkBlue);
62 //![2]
61 //![2]
63
62
64 //![3]
63 //![3]
65 QMainWindow window;
64 QMainWindow window;
66 QChartView* chartView = new QChartView(donutBreakdown);
65 QChartView* chartView = new QChartView(donutBreakdown);
67 chartView->setRenderHint(QPainter::Antialiasing);
66 chartView->setRenderHint(QPainter::Antialiasing);
68 window.setCentralWidget(chartView);
67 window.setCentralWidget(chartView);
69 window.resize(800, 600);
68 window.resize(800, 600);
70 window.show();
69 window.show();
71 //![3]
70 //![3]
71
72 // Data is taken from Statistics Finland:
73 // http://www.stat.fi/til/ekul/2010/ekul_2010_2011-12-13_tie_001_en.html
74 window.statusBar()->setFont(QFont("Arial", 7));
75 window.statusBar()->showMessage("Graph is based on data of 'Total consumption of energy increased by 10 per cent in 2010' Statistics Finland, 13 December 2011");
72
76
73 return a.exec();
77 return a.exec();
74 }
78 }
General Comments 0
You need to be logged in to leave comments. Login now