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 <QtWidgets/QApplication> |
31 | #include <QtWidgets/QMainWindow> |
32 | #include <QtCharts/QChartView> |
33 | #include <QtCharts/QLineSeries> |
34 | #include <QtCharts/QSplineSeries> |
35 | #include <QtCharts/QValueAxis> |
36 | #include <QtCharts/QCategoryAxis> |
37 | |
38 | QT_CHARTS_USE_NAMESPACE |
39 | |
40 | int main(int argc, char *argv[]) |
41 | { |
42 | QApplication a(argc, argv); |
43 | |
44 | //![1] |
45 | QChart *chart = new QChart(); |
46 | chart->legend()->hide(); |
47 | chart->setTitle("Multiaxis chart example" ); |
48 | //![1] |
49 | |
50 | //![2] |
51 | QValueAxis *axisX = new QValueAxis; |
52 | axisX->setTickCount(10); |
53 | chart->addAxis(axis: axisX, alignment: Qt::AlignBottom); |
54 | //![2] |
55 | |
56 | //![3] |
57 | QSplineSeries *series = new QSplineSeries; |
58 | *series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5); |
59 | chart->addSeries(series); |
60 | |
61 | QValueAxis *axisY = new QValueAxis; |
62 | axisY->setLinePenColor(series->pen().color()); |
63 | |
64 | chart->addAxis(axis: axisY, alignment: Qt::AlignLeft); |
65 | series->attachAxis(axis: axisX); |
66 | series->attachAxis(axis: axisY); |
67 | //![3] |
68 | |
69 | //![4] |
70 | series = new QSplineSeries; |
71 | *series << QPointF(1, 0.5) << QPointF(1.5, 4.5) << QPointF(2.4, 2.5) << QPointF(4.3, 12.5) |
72 | << QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17); |
73 | chart->addSeries(series); |
74 | |
75 | QCategoryAxis *axisY3 = new QCategoryAxis; |
76 | axisY3->append(label: "Low" , categoryEndValue: 5); |
77 | axisY3->append(label: "Medium" , categoryEndValue: 12); |
78 | axisY3->append(label: "High" , categoryEndValue: 17); |
79 | axisY3->setLinePenColor(series->pen().color()); |
80 | axisY3->setGridLinePen((series->pen())); |
81 | |
82 | chart->addAxis(axis: axisY3, alignment: Qt::AlignRight); |
83 | series->attachAxis(axis: axisX); |
84 | series->attachAxis(axis: axisY3); |
85 | //![4] |
86 | |
87 | //![5] |
88 | QChartView *chartView = new QChartView(chart); |
89 | chartView->setRenderHint(hint: QPainter::Antialiasing); |
90 | //![5] |
91 | |
92 | //![6] |
93 | QMainWindow window; |
94 | window.setCentralWidget(chartView); |
95 | window.resize(w: 800, h: 600); |
96 | window.show(); |
97 | //![6] |
98 | |
99 | return a.exec(); |
100 | } |
101 | |
102 | |