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 <QtCharts/QScatterSeries>
32#include <QtCharts/QLegendMarker>
33#include <QtGui/QImage>
34#include <QtGui/QPainter>
35#include <QtCore/QtMath>
36
37ChartView::ChartView(QWidget *parent) :
38 QChartView(new QChart(), parent)
39{
40 //![1]
41 QScatterSeries *series0 = new QScatterSeries();
42 series0->setName("scatter1");
43 series0->setMarkerShape(QScatterSeries::MarkerShapeCircle);
44 series0->setMarkerSize(15.0);
45
46 QScatterSeries *series1 = new QScatterSeries();
47 series1->setName("scatter2");
48 series1->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
49 series1->setMarkerSize(20.0);
50
51 QScatterSeries *series2 = new QScatterSeries();
52 series2->setName("scatter3");
53 series2->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
54 series2->setMarkerSize(30.0);
55 //![1]
56
57 //![2]
58 series0->append(x: 0, y: 6);
59 series0->append(x: 2, y: 4);
60 series0->append(x: 3, y: 8);
61 series0->append(x: 7, y: 4);
62 series0->append(x: 10, y: 5);
63
64 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
65 *series2 << QPointF(1, 5) << QPointF(4, 6) << QPointF(6, 3) << QPointF(9, 5);
66 //![2]
67
68 //![3]
69 QPainterPath starPath;
70 starPath.moveTo(x: 28, y: 15);
71 for (int i = 1; i < 5; ++i) {
72 starPath.lineTo(x: 14 + 14 * qCos(v: 0.8 * i * M_PI),
73 y: 15 + 14 * qSin(v: 0.8 * i * M_PI));
74 }
75 starPath.closeSubpath();
76
77 QImage star(30, 30, QImage::Format_ARGB32);
78 star.fill(color: Qt::transparent);
79
80 QPainter painter(&star);
81 painter.setRenderHint(hint: QPainter::Antialiasing);
82 painter.setPen(QRgb(0xf6a625));
83 painter.setBrush(painter.pen().color());
84 painter.drawPath(path: starPath);
85
86 series2->setBrush(star);
87 series2->setPen(QColor(Qt::transparent));
88 //![3]
89
90 //![4]
91 setRenderHint(hint: QPainter::Antialiasing);
92 chart()->addSeries(series: series0);
93 chart()->addSeries(series: series1);
94 chart()->addSeries(series: series2);
95
96 chart()->setTitle("Simple scatterchart example");
97 chart()->createDefaultAxes();
98 chart()->setDropShadowEnabled(false);
99 //![4]
100
101 //![5]
102 chart()->legend()->setMarkerShape(QLegend::MarkerShapeFromSeries);
103 //![5]
104}
105

source code of qtcharts/examples/charts/scatterchart/chartview.cpp