| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses |
| 5 |
|
| 6 |
#include "charts.h" |
| 7 |
#include <QtCharts/QChart> |
| 8 |
#include <QtCharts/QLineSeries> |
| 9 |
|
| 10 |
class LineChart: public Chart |
| 11 |
{ |
| 12 |
public: |
| 13 |
QString name() { return QObject::tr("LineChart"); } |
| 14 |
QString category() { return QObject::tr("XYSeries"); } |
| 15 |
QString subCategory() { return QString(); } |
| 16 |
|
| 17 |
QChart *createChart(const DataTable &table) |
| 18 |
{ |
| 19 |
QChart *chart = new QChart(); |
| 20 |
chart->setTitle("Line chart"); |
| 21 |
QString name("Series "); |
| 22 |
int nameIndex = 0; |
| 23 |
foreach (DataList list, table) { |
| 24 |
QLineSeries *series = new QLineSeries(chart); |
| 25 |
foreach (Data data, list) |
| 26 |
series->append(data.first); |
| 27 |
series->setName(name + QString::number(nameIndex)); |
| 28 |
nameIndex++; |
| 29 |
chart->addSeries(series); |
| 30 |
} |
| 31 |
chart->createDefaultAxes(); |
| 32 |
return chart; |
| 33 |
} |
| 34 |
}; |
| 35 |
|
| 36 |
DECLARE_CHART(LineChart) |
| 37 |
|