| 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/QScatterSeries> |
| 9 |
#include <QtCharts/QLogValueAxis> |
| 10 |
#include <QtCharts/QValueAxis> |
| 11 |
|
| 12 |
class ScatterXLogY: public Chart |
| 13 |
{ |
| 14 |
public: |
| 15 |
QString name() { return "Scatter X LogY"; } |
| 16 |
QString category() { return QObject::tr("Domain"); } |
| 17 |
QString subCategory() { return QObject::tr("Both Log"); } |
| 18 |
|
| 19 |
QChart *createChart(const DataTable &table) |
| 20 |
{ |
| 21 |
QChart *chart = new QChart(); |
| 22 |
chart->setTitle("Scatter: X, Log Y"); |
| 23 |
|
| 24 |
QString name("Series "); |
| 25 |
int nameIndex = 0; |
| 26 |
foreach (DataList list, table) { |
| 27 |
QScatterSeries *series = new QScatterSeries(chart); |
| 28 |
foreach (Data data, list) |
| 29 |
series->append(data.first); |
| 30 |
series->setName(name + QString::number(nameIndex)); |
| 31 |
nameIndex++; |
| 32 |
chart->addSeries(series); |
| 33 |
} |
| 34 |
|
| 35 |
QValueAxis *axisX= new QValueAxis(); |
| 36 |
QLogValueAxis *axisY= new QLogValueAxis(); |
| 37 |
axisY->setBase(2); |
| 38 |
foreach (QAbstractSeries *series, chart->series()) { |
| 39 |
chart->setAxisX(axisX, series); |
| 40 |
chart->setAxisY(axisY, series); |
| 41 |
} |
| 42 |
|
| 43 |
return chart; |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
DECLARE_CHART(ScatterXLogY); |