1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | #include <QtWidgets/QApplication> |
30 | #include <QtWidgets/QMainWindow> |
31 | #include <QtWidgets/QStatusBar> |
32 | #include <QtCharts/QChartView> |
33 | #include "donutbreakdownchart.h" |
34 | |
35 | QT_CHARTS_USE_NAMESPACE |
36 | |
37 | int main(int argc, char *argv[]) |
38 | { |
39 | QApplication a(argc, argv); |
40 | |
41 | //![1] |
42 | // Graph is based on data of 'Total consumption of energy increased by 10 per cent in 2010' |
43 | // Statistics Finland, 13 December 2011 |
44 | // http://www.stat.fi/til/ekul/2010/ekul_2010_2011-12-13_tie_001_en.html |
45 | |
46 | QPieSeries *series1 = new QPieSeries(); |
47 | series1->setName("Fossil fuels" ); |
48 | series1->append(label: "Oil" , value: 353295); |
49 | series1->append(label: "Coal" , value: 188500); |
50 | series1->append(label: "Natural gas" , value: 148680); |
51 | series1->append(label: "Peat" , value: 94545); |
52 | |
53 | QPieSeries *series2 = new QPieSeries(); |
54 | series2->setName("Renewables" ); |
55 | series2->append(label: "Wood fuels" , value: 319663); |
56 | series2->append(label: "Hydro power" , value: 45875); |
57 | series2->append(label: "Wind power" , value: 1060); |
58 | |
59 | QPieSeries *series3 = new QPieSeries(); |
60 | series3->setName("Others" ); |
61 | series3->append(label: "Nuclear energy" , value: 238789); |
62 | series3->append(label: "Import energy" , value: 37802); |
63 | series3->append(label: "Other" , value: 32441); |
64 | //![1] |
65 | |
66 | //![2] |
67 | DonutBreakdownChart *donutBreakdown = new DonutBreakdownChart(); |
68 | donutBreakdown->setAnimationOptions(QChart::AllAnimations); |
69 | donutBreakdown->setTitle("Total consumption of energy in Finland 2010" ); |
70 | donutBreakdown->legend()->setAlignment(Qt::AlignRight); |
71 | donutBreakdown->addBreakdownSeries(series: series1, color: Qt::red); |
72 | donutBreakdown->addBreakdownSeries(series: series2, color: Qt::darkGreen); |
73 | donutBreakdown->addBreakdownSeries(series: series3, color: Qt::darkBlue); |
74 | //![2] |
75 | |
76 | //![3] |
77 | QMainWindow window; |
78 | QChartView *chartView = new QChartView(donutBreakdown); |
79 | chartView->setRenderHint(hint: QPainter::Antialiasing); |
80 | window.setCentralWidget(chartView); |
81 | window.resize(w: 800, h: 500); |
82 | window.show(); |
83 | //![3] |
84 | |
85 | return a.exec(); |
86 | } |
87 | |