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