-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpiechart.cc
More file actions
43 lines (35 loc) · 1.11 KB
/
Copy pathpiechart.cc
File metadata and controls
43 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "piechart.hpp"
#include "normalchartdata.hpp"
class PieChart::PieChartPrivate
{
public:
explicit PieChartPrivate(ChartView *parent) : q_ptr(parent)
{
pieSeries = new QPieSeries(q_ptr);
chart = new QChart;
chart->setAnimationOptions(QChart::AllAnimations);
chart->setTitle(QObject::tr("Pie Chart"));
}
ChartView *q_ptr;
QChart *chart;
QPieSeries *pieSeries;
};
PieChart::PieChart(QWidget *parent) : ChartView(parent), d_ptr(new PieChartPrivate(this))
{ setupUI(); }
PieChart::~PieChart() = default;
void PieChart::setupUI()
{
setRenderHint(QPainter::Antialiasing);
setChart(d_ptr->chart);
PointList pointList = generateRandomDataPoints(5, 100);
for (int i = 0; i < pointList.size(); i++) {
QPieSlice *slice = d_ptr->pieSeries->append(tr("P%1").arg(i), pointList[i].y());
if (i == 0) {
// Show the first slice exploded with label
slice->setLabelVisible();
slice->setExploded();
//slice->setExplodeDistanceFactor(0.5);
}
}
d_ptr->chart->addSeries(d_ptr->pieSeries);
}