##// END OF EJS Templates
Added basic donut chart example. Still better data needed
Marek Rosa -
r1841:e5aa797837ba
parent child
Show More
@@ -0,0 +1,5
1 !include( ../examples.pri ) {
2 error( "Couldn't find the examples.pri file!" )
3 }
4 TARGET = donutchart
5 SOURCES += main.cpp
@@ -0,0 +1,70
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include <QApplication>
22 #include <QMainWindow>
23 #include <QChartView>
24 #include <QPieSeries>
25 #include <QPieSlice>
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
29 int main(int argc, char *argv[])
30 {
31 QApplication a(argc, argv);
32
33 //![1]
34 QPieSeries *series = new QPieSeries();
35 series->setHoleSize(0.35);
36 series->append("Jane", 1);
37 series->append("Joe", 2);
38 series->append("Andy", 3);
39 series->append("Barbara", 4);
40 series->append("Axel", 5);
41 //![1]
42
43 //![2]
44 QPieSlice *slice = series->slices().at(1);
45 slice->setExploded();
46 slice->setLabelVisible();
47 slice->setPen(QPen(Qt::darkGreen, 2));
48 slice->setBrush(Qt::green);
49 //![2]
50
51 //![3]
52 QChart* chart = new QChart();
53 chart->addSeries(series);
54 chart->setTitle("Simple donutchart example");
55 //![3]
56
57 //![4]
58 QChartView* chartView = new QChartView(chart);
59 chartView->setRenderHint(QPainter::Antialiasing);
60 //![4]
61
62 //![5]
63 QMainWindow window;
64 window.setCentralWidget(chartView);
65 window.resize(400, 300);
66 window.show();
67 //![5]
68
69 return a.exec();
70 }
@@ -31,4 +31,5 SUBDIRS += \
31 donutbreakdown \
31 donutbreakdown \
32 scrollchart \
32 scrollchart \
33 datetimeaxis \
33 datetimeaxis \
34 populationpyramid
34 populationpyramid \
35 donutchart
@@ -169,8 +169,17 void PieSliceItem::updateGeometry()
169 m_labelTextRect.moveBottomLeft(labelTextStart);
169 m_labelTextRect.moveBottomLeft(labelTextStart);
170 break;
170 break;
171 case QPieSlice::LabelInsideHorizontal:
171 case QPieSlice::LabelInsideHorizontal:
172 case QPieSlice::LabelInsideTangential:
172 case QPieSlice::LabelInsideTangential:{
173 QPointF textCenter;
174 if (m_data.m_holeRadius > 0)
175 textCenter = m_data.m_center + offset(centerAngle, m_data.m_holeRadius + (m_data.m_radius - m_data.m_holeRadius) / 2);
176 else
177 textCenter = m_data.m_center + offset(centerAngle, m_data.m_radius / 2);
178 m_labelTextRect.moveCenter(textCenter);
179 break;
180 }
173 case QPieSlice::LabelInsideNormal:{
181 case QPieSlice::LabelInsideNormal:{
182 // TODO: align the label text to the slice arc insead of half the radius
174 QPointF textCenter;
183 QPointF textCenter;
175 if (m_data.m_holeRadius > 0)
184 if (m_data.m_holeRadius > 0)
176 textCenter = m_data.m_center + offset(centerAngle, m_data.m_holeRadius + (m_data.m_radius - m_data.m_holeRadius) / 2);
185 textCenter = m_data.m_center + offset(centerAngle, m_data.m_holeRadius + (m_data.m_radius - m_data.m_holeRadius) / 2);
@@ -741,7 +741,6 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
741 m_pieStartAngle(0),
741 m_pieStartAngle(0),
742 m_pieEndAngle(360),
742 m_pieEndAngle(360),
743 m_sum(0),
743 m_sum(0),
744 // m_donutChart(false),
745 m_holeRelativeSize(0.0)
744 m_holeRelativeSize(0.0)
746 {
745 {
747 }
746 }
General Comments 0
You need to be logged in to leave comments. Login now