| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 or (at your option) any later version | 
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by | 
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 | 
| 22 | ** included in the packaging of this file. Please review the following | 
| 23 | ** information to ensure the GNU General Public License requirements will | 
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 25 | ** | 
| 26 | ** $QT_END_LICENSE$ | 
| 27 | ** | 
| 28 | ****************************************************************************/ | 
| 29 |  | 
| 30 | #include "chartview.h" | 
| 31 | #include <QtWidgets/QApplication> | 
| 32 | #include <QtWidgets/QMainWindow> | 
| 33 | #include <QtCharts/QScatterSeries> | 
| 34 | #include <QtCharts/QLineSeries> | 
| 35 | #include <QtCharts/QSplineSeries> | 
| 36 | #include <QtCharts/QAreaSeries> | 
| 37 | #include <QtCharts/QValueAxis> | 
| 38 | #include <QtCharts/QPolarChart> | 
| 39 | #include <QtCore/QDebug> | 
| 40 |  | 
| 41 | QT_CHARTS_USE_NAMESPACE | 
| 42 |  | 
| 43 | int main(int argc, char *argv[]) | 
| 44 | { | 
| 45 |     QApplication a(argc, argv); | 
| 46 |  | 
| 47 |     const qreal angularMin = -100; | 
| 48 |     const qreal angularMax = 100; | 
| 49 |  | 
| 50 |     const qreal radialMin = -100; | 
| 51 |     const qreal radialMax = 100; | 
| 52 |  | 
| 53 |     QScatterSeries *series1 = new QScatterSeries(); | 
| 54 |     series1->setName("scatter" ); | 
| 55 |     for (int i = angularMin; i <= angularMax; i += 10) | 
| 56 |         series1->append(x: i, y: (i / radialMax) * radialMax + 8.0); | 
| 57 |  | 
| 58 |     QSplineSeries *series2 = new QSplineSeries(); | 
| 59 |     series2->setName("spline" ); | 
| 60 |     for (int i = angularMin; i <= angularMax; i += 10) | 
| 61 |         series2->append(x: i, y: (i / radialMax) * radialMax); | 
| 62 |  | 
| 63 |     QLineSeries *series3 = new QLineSeries(); | 
| 64 |     series3->setName("star outer" ); | 
| 65 |     qreal ad = (angularMax - angularMin) / 8; | 
| 66 |     qreal rd = (radialMax - radialMin) / 3 * 1.3; | 
| 67 |     series3->append(x: angularMin, y: radialMax); | 
| 68 |     series3->append(x: angularMin + ad*1, y: radialMin + rd); | 
| 69 |     series3->append(x: angularMin + ad*2, y: radialMax); | 
| 70 |     series3->append(x: angularMin + ad*3, y: radialMin + rd); | 
| 71 |     series3->append(x: angularMin + ad*4, y: radialMax); | 
| 72 |     series3->append(x: angularMin + ad*5, y: radialMin + rd); | 
| 73 |     series3->append(x: angularMin + ad*6, y: radialMax); | 
| 74 |     series3->append(x: angularMin + ad*7, y: radialMin + rd); | 
| 75 |     series3->append(x: angularMin + ad*8, y: radialMax); | 
| 76 |  | 
| 77 |     QLineSeries *series4 = new QLineSeries(); | 
| 78 |     series4->setName("star inner" ); | 
| 79 |     ad = (angularMax - angularMin) / 8; | 
| 80 |     rd = (radialMax - radialMin) / 3; | 
| 81 |     series4->append(x: angularMin, y: radialMax); | 
| 82 |     series4->append(x: angularMin + ad*1, y: radialMin + rd); | 
| 83 |     series4->append(x: angularMin + ad*2, y: radialMax); | 
| 84 |     series4->append(x: angularMin + ad*3, y: radialMin + rd); | 
| 85 |     series4->append(x: angularMin + ad*4, y: radialMax); | 
| 86 |     series4->append(x: angularMin + ad*5, y: radialMin + rd); | 
| 87 |     series4->append(x: angularMin + ad*6, y: radialMax); | 
| 88 |     series4->append(x: angularMin + ad*7, y: radialMin + rd); | 
| 89 |     series4->append(x: angularMin + ad*8, y: radialMax); | 
| 90 |  | 
| 91 |     QAreaSeries *series5 = new QAreaSeries(); | 
| 92 |     series5->setName("star area" ); | 
| 93 |     series5->setUpperSeries(series3); | 
| 94 |     series5->setLowerSeries(series4); | 
| 95 |     series5->setOpacity(0.5); | 
| 96 |  | 
| 97 |     //![1] | 
| 98 |     QPolarChart *chart = new QPolarChart(); | 
| 99 |     //![1] | 
| 100 |     chart->addSeries(series: series1); | 
| 101 |     chart->addSeries(series: series2); | 
| 102 |     chart->addSeries(series: series3); | 
| 103 |     chart->addSeries(series: series4); | 
| 104 |     chart->addSeries(series: series5); | 
| 105 |  | 
| 106 |     chart->setTitle("Use arrow keys to scroll, +/- to zoom, and space to switch chart type." ); | 
| 107 |  | 
| 108 |     //![2] | 
| 109 |     QValueAxis *angularAxis = new QValueAxis(); | 
| 110 |     angularAxis->setTickCount(9); // First and last ticks are co-located on 0/360 angle. | 
| 111 |     angularAxis->setLabelFormat("%.1f" ); | 
| 112 |     angularAxis->setShadesVisible(true); | 
| 113 |     angularAxis->setShadesBrush(QBrush(QColor(249, 249, 255))); | 
| 114 |     chart->addAxis(axis: angularAxis, polarOrientation: QPolarChart::PolarOrientationAngular); | 
| 115 |  | 
| 116 |     QValueAxis *radialAxis = new QValueAxis(); | 
| 117 |     radialAxis->setTickCount(9); | 
| 118 |     radialAxis->setLabelFormat("%d" ); | 
| 119 |     chart->addAxis(axis: radialAxis, polarOrientation: QPolarChart::PolarOrientationRadial); | 
| 120 |     //![2] | 
| 121 |  | 
| 122 |     series1->attachAxis(axis: radialAxis); | 
| 123 |     series1->attachAxis(axis: angularAxis); | 
| 124 |     series2->attachAxis(axis: radialAxis); | 
| 125 |     series2->attachAxis(axis: angularAxis); | 
| 126 |     series3->attachAxis(axis: radialAxis); | 
| 127 |     series3->attachAxis(axis: angularAxis); | 
| 128 |     series4->attachAxis(axis: radialAxis); | 
| 129 |     series4->attachAxis(axis: angularAxis); | 
| 130 |     series5->attachAxis(axis: radialAxis); | 
| 131 |     series5->attachAxis(axis: angularAxis); | 
| 132 |  | 
| 133 |     radialAxis->setRange(min: radialMin, max: radialMax); | 
| 134 |     angularAxis->setRange(min: angularMin, max: angularMax); | 
| 135 |  | 
| 136 |     ChartView *chartView = new ChartView(); | 
| 137 |     chartView->setChart(chart); | 
| 138 |     chartView->setRenderHint(hint: QPainter::Antialiasing); | 
| 139 |  | 
| 140 |     QMainWindow window; | 
| 141 |     window.setCentralWidget(chartView); | 
| 142 |     window.resize(w: 800, h: 600); | 
| 143 |     window.show(); | 
| 144 |  | 
| 145 |     return a.exec(); | 
| 146 | } | 
| 147 |  |