| 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 |
#include <QtCharts/QLogValueAxis> |
| 10 |
#include <QtCharts/QCategoryAxis> |
| 11 |
|
| 12 |
class LogValueAxisY: public Chart |
| 13 |
{ |
| 14 |
public: |
| 15 |
QString name() { return "LogValueAxisY"; } |
| 16 |
QString category() { return QObject::tr("Axis"); } |
| 17 |
QString subCategory() { return QObject::tr("Log"); } |
| 18 |
|
| 19 |
QChart *createChart(const DataTable &table) |
| 20 |
{ |
| 21 |
QChart *chart = new QChart(); |
| 22 |
chart->setTitle("Value X , LogValue Y"); |
| 23 |
|
| 24 |
QString name("Series "); |
| 25 |
int nameIndex = 0; |
| 26 |
foreach (DataList list, table) { |
| 27 |
QLineSeries *series = new QLineSeries(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 |
chart->createDefaultAxes(); |
| 36 |
QLogValueAxis *axis = new QLogValueAxis(); |
| 37 |
axis->setBase(2); |
| 38 |
foreach (QAbstractSeries *series, chart->series()) |
| 39 |
chart->setAxisY(axis, series); |
| 40 |
|
| 41 |
return chart; |
| 42 |
} |
| 43 |
}; |
| 44 |
|
| 45 |
class LogValueAxisTitleY: public LogValueAxisY |
| 46 |
{ |
| 47 |
public: |
| 48 |
QString name() { return "LogValueAxisYTitle"; } |
| 49 |
|
| 50 |
QChart *createChart(const DataTable &table) |
| 51 |
{ |
| 52 |
QChart *chart = LogValueAxisY::createChart(table); |
| 53 |
chart->axisX()->setTitleText("Axis X"); |
| 54 |
chart->axisY()->setTitleText("Axis Y"); |
| 55 |
chart->setTitle("Value X , Log Value Y, title"); |
| 56 |
return chart; |
| 57 |
} |
| 58 |
}; |
| 59 |
|
| 60 |
DECLARE_CHART(LogValueAxisY); |
| 61 |
DECLARE_CHART(LogValueAxisTitleY); |