-
Notifications
You must be signed in to change notification settings - Fork 12
/
areachart.cpp
54 lines (47 loc) · 1.4 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
#include "areachart.h"
#include "normalchartdata.h"
class AreaChart::AreaChartPrivate
{
public:
explicit AreaChartPrivate(ChartView *q)
: q_ptr(q)
{
areaSeries = new QAreaSeries(q_ptr);
scatterSeries = new QScatterSeries(q_ptr);
scatterSeries->setMarkerSize(8);
chart = new QChart;
chart->setTitle(QObject::tr("Area Chart"));
chart->addSeries(areaSeries);
chart->addSeries(scatterSeries);
chart->createDefaultAxes();
chart->axes(Qt::Horizontal).first()->setRange(0, 100);
chart->axes(Qt::Vertical).first()->setRange(0, 100);
}
ChartView *q_ptr;
QChart *chart;
QAreaSeries *areaSeries;
QScatterSeries *scatterSeries;
};
AreaChart::AreaChart(QWidget *parent)
: ChartView(parent)
, d_ptr(new AreaChartPrivate(this))
{
setupUI();
}
AreaChart::~AreaChart() = default;
void AreaChart::setupUI()
{
setRenderHint(QPainter::Antialiasing);
setChart(d_ptr->chart);
PointList pointList = generateRandomDataPoints(5, 101);
d_ptr->scatterSeries->replace(pointList);
auto *upperSeries = new QLineSeries(this);
auto *lowerSeries = new QLineSeries(this);
upperSeries->replace(pointList);
for (auto &i : pointList) {
i.setY(0);
}
lowerSeries->replace(pointList);
d_ptr->areaSeries->setUpperSeries(upperSeries);
d_ptr->areaSeries->setLowerSeries(lowerSeries);
}