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/QAreaSeries> |
35 | |
36 | QT_CHARTS_USE_NAMESPACE |
37 | |
38 | int main(int argc, char *argv[]) |
39 | { |
40 | QApplication a(argc, argv); |
41 | |
42 | //![1] |
43 | QLineSeries *series0 = new QLineSeries(); |
44 | QLineSeries *series1 = new QLineSeries(); |
45 | //![1] |
46 | |
47 | //![2] |
48 | *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6) |
49 | << QPointF(16, 7) << QPointF(18, 5); |
50 | *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3) |
51 | << QPointF(16, 4) << QPointF(18, 3); |
52 | //![2] |
53 | |
54 | //![3] |
55 | QAreaSeries *series = new QAreaSeries(series0, series1); |
56 | series->setName("Batman" ); |
57 | QPen pen(0x059605); |
58 | pen.setWidth(3); |
59 | series->setPen(pen); |
60 | |
61 | QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1)); |
62 | gradient.setColorAt(pos: 0.0, color: 0x3cc63c); |
63 | gradient.setColorAt(pos: 1.0, color: 0x26f626); |
64 | gradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
65 | series->setBrush(gradient); |
66 | //![3] |
67 | |
68 | //![4] |
69 | QChart *chart = new QChart(); |
70 | chart->addSeries(series); |
71 | chart->setTitle("Simple areachart example" ); |
72 | chart->createDefaultAxes(); |
73 | chart->axes(orientation: Qt::Horizontal).first()->setRange(min: 0, max: 20); |
74 | chart->axes(orientation: Qt::Vertical).first()->setRange(min: 0, max: 10); |
75 | //![4] |
76 | |
77 | //![5] |
78 | QChartView *chartView = new QChartView(chart); |
79 | chartView->setRenderHint(hint: QPainter::Antialiasing); |
80 | //![5] |
81 | |
82 | //![6] |
83 | QMainWindow window; |
84 | window.setCentralWidget(chartView); |
85 | window.resize(w: 400, h: 300); |
86 | window.show(); |
87 | //![6] |
88 | |
89 | return a.exec(); |
90 | } |
91 | |