-
Notifications
You must be signed in to change notification settings - Fork 0
/
datavisualizer.cpp
38 lines (28 loc) · 1.15 KB
/
datavisualizer.cpp
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
#include "datavisualizer.h"
DataVisualizer::DataVisualizer()
{
}
void DataVisualizer::RenderChart(QWidget *frame, int incomeBalance, int expenseBalance)
{
QPieSeries *series = new QPieSeries();
series->append("INCOME", incomeBalance)->setBrush(Qt::green);
series->append("EXPENSES", expenseBalance)->setBrush(Qt::red);
QPieSlice *sliceIn = series->slices().at(0);
sliceIn->setLabel("Income " + QString("%1%").arg(100*sliceIn->percentage(), 0, 'f', 1));
QPieSlice *sliceEx = series->slices().at(1);
sliceEx->setLabel("Expense " + QString("%1%").arg(100*sliceEx->percentage(), 0, 'f', 1));
if(!(incomeBalance <= 0 && expenseBalance <= 0))
{
series->setLabelsVisible();
series->setLabelsPosition(QPieSlice::LabelOutside);
sliceEx->setLabelVisible(true);
sliceIn->setLabelVisible(true);
}
qDebug() << "Rendering Charts" << incomeBalance << expenseBalance;
QChart *chart = new QChart();
chart->addSeries(series);
chart->setTitle("Cash Flow");
QChartView *chartView = new QChartView(chart);
chartView->setParent(frame);
chartView->resize(frame->width(), frame->height());
}