-
Notifications
You must be signed in to change notification settings - Fork 0
/
areachart.cpp
61 lines (49 loc) · 1.81 KB
/
areachart.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "areachart.h"
AreaChart::AreaChart(DataModel *model): BaseChart(model),XAxis(new QCategoryAxis()), YAxis(new QValueAxis()){}
AreaChart::~AreaChart()
{
delete XAxis;
delete YAxis;
}
void AreaChart::dataToSeries(QChart *chart)
{
std::vector<std::vector<float>> data = model->getData();
std::vector<QVariant> rowHeader = model->getRowHeader();
std::vector<QLineSeries *> sets;
for (int i = 0; i < model->rowCount(); i++)
{
QLineSeries *series = new QLineSeries;
series->setName(rowHeader[i].toString());
for (int j = 0; j < model->columnCount(); j++)
series->append(QPointF(j, data[i].at(j)));
QAreaSeries *AreaSerie= new QAreaSeries(series);
AreaSerie->setName(rowHeader[i].toString());
chart->addSeries(AreaSerie);
sets.push_back(series);
AreaSerie->attachAxis(XAxis);
AreaSerie->attachAxis(YAxis);
}
XAxis->setRange(0, model->columnCount()-1 > 0 ? model->columnCount()-1 : model->columnCount());
float min = model->min();
float max = model->max();
if (min < max)
YAxis->setRange(model->min(), model->max());
else
YAxis->setRange(model->min(), model->min()+1);
}
QChart *AreaChart::toChart()
{
std::vector<QVariant> colHeader = model->getColHeader();
QChart *chart = new QChart();
chart->setTitle("Area Chart");
chart->setAnimationOptions(QChart::AllAnimations);
for(int i = 0; i < model->columnCount(); i++)
XAxis->append(colHeader[i].toString(), i);
XAxis->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
chart->addAxis(XAxis, Qt::AlignBottom);
chart->addAxis(YAxis, Qt::AlignLeft);
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);
AreaChart::dataToSeries(chart);
return chart;
}