##// END OF EJS Templates
update donutchart example
Jani Honkonen -
r1858:f0be46ef9f91
parent child
Show More
@@ -1,71 +1,62
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
20
21 #include <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPieSeries>
24 #include <QPieSeries>
25 #include <QPieSlice>
25 #include <QPieSlice>
26
26 #include <QDebug>
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
30 {
30 {
31 QApplication a(argc, argv);
31 QApplication a(argc, argv);
32
32
33 //![1]
33 //![1]
34 QPieSeries *series = new QPieSeries();
34 QPieSeries *series = new QPieSeries();
35 series->setHoleSize(0.35);
35 series->setHoleSize(0.35);
36 series->append("Jane", 1);
36 series->append("Protein 4.2%", 4.2);
37 series->append("Joe", 2);
37 QPieSlice *slice = series->append("Fat 15.6%", 15.6);
38 series->append("Andy", 3);
38 slice->setExploded();
39 series->append("Barbara", 4);
39 slice->setLabelVisible();
40 series->append("Axel", 5);
40 series->append("Other 23.8%", 23.8);
41 series->append("Carbs 56.4%", 56.4);
41 //![1]
42 //![1]
42
43
43 //![2]
44 //![2]
44 QPieSlice *slice = series->slices().at(1);
45 QChartView* chartView = new QChartView();
45 slice->setExploded();
46 chartView->setRenderHint(QPainter::Antialiasing);
46 slice->setLabelVisible();
47 chartView->chart()->setTitle("Donut with a lemon glaze (100g)");
47 slice->setPen(QPen(Qt::darkGreen, 2));
48 chartView->chart()->addSeries(series);
48 slice->setBrush(Qt::green);
49 chartView->chart()->legend()->setAlignment(Qt::AlignBottom);
50 chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean);
51 chartView->chart()->legend()->setFont(QFont("Arial", 7));
49 //![2]
52 //![2]
50
53
51 //![3]
54 //![3]
52 QChart* chart = new QChart();
53 chart->addSeries(series);
54 chart->setTitle("Simple donutchart example");
55 chart->legend()->hide();
56 //![3]
57
58 //![4]
59 QChartView* chartView = new QChartView(chart);
60 chartView->setRenderHint(QPainter::Antialiasing);
61 //![4]
62
63 //![5]
64 QMainWindow window;
55 QMainWindow window;
65 window.setCentralWidget(chartView);
56 window.setCentralWidget(chartView);
66 window.resize(400, 300);
57 window.resize(400, 300);
67 window.show();
58 window.show();
68 //![5]
59 //![3]
69
60
70 return a.exec();
61 return a.exec();
71 }
62 }
General Comments 0
You need to be logged in to leave comments. Login now