| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include "charts.h" |
| 5 |
#include <QtCharts/QChart> |
| 6 |
#include <QtCharts/QAreaSeries> |
| 7 |
#include <QtCharts/QLineSeries> |
| 8 |
|
| 9 |
class AreaChart: public Chart |
| 10 |
{ |
| 11 |
public: |
| 12 |
QString name() { return QObject::tr("AreaChart"); } |
| 13 |
QString category() { return QObject::tr("XYSeries"); } |
| 14 |
QString subCategory() { return QString(); } |
| 15 |
|
| 16 |
QChart *createChart(const DataTable &table) |
| 17 |
{ |
| 18 |
QChart *chart = new QChart(); |
| 19 |
chart->setTitle("Area chart"); |
| 20 |
|
| 21 |
// The lower series initialized to zero values |
| 22 |
QLineSeries *lowerSeries = 0; |
| 23 |
QString name("Series "); |
| 24 |
int nameIndex = 0; |
| 25 |
for (int i(0); i < table.count(); i++) { |
| 26 |
QLineSeries *upperSeries = new QLineSeries(chart); |
| 27 |
for (int j(0); j < table[i].count(); j++) { |
| 28 |
Data data = table[i].at(j); |
| 29 |
if (lowerSeries) { |
| 30 |
const QList<QPointF>& points = lowerSeries->points(); |
| 31 |
upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
| 32 |
} else { |
| 33 |
upperSeries->append(QPointF(j, data.first.y())); |
| 34 |
} |
| 35 |
} |
| 36 |
QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
| 37 |
area->setName(name + QString::number(nameIndex)); |
| 38 |
nameIndex++; |
| 39 |
chart->addSeries(area); |
| 40 |
chart->createDefaultAxes(); |
| 41 |
lowerSeries = upperSeries; |
| 42 |
} |
| 43 |
return chart; |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
DECLARE_CHART(AreaChart) |
| 48 |
|