summaryrefslogtreecommitdiffstats
path: root/src/charts/doc/src/examples-lineandbarchart.qdoc
blob: 227a07402dfc0fd4f24ae286b162b18ed280bb7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/******************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the Qt Charts module.
**
** $QT_BEGIN_LICENSE:COMM$
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
******************************************************************************/

/*!
    \example lineandbar
    \title Line and BarChart Example
    \ingroup qtcharts_examples

    \brief The example shows how to combine different charts and set the axes.

    In the example we combine a linechart with
    a barchart and use the category axis as a common axis for both.

    \image examples_lineandbar.png

    Here we create data for our bar series.

    \snippet lineandbar/main.cpp 1

    We create a bar series and append sets to it.
    The first values of each set are grouped together in the first category, the second values in the second category and so on.

    \snippet lineandbar/main.cpp 2

    Then we create a line series and add data to it. To make the data match with the barchart, we use the index as an x-value for our line series, so that
    first point is at (0,value) second at (1,value) and so on.

    \snippet lineandbar/main.cpp 8

    Here we create the chart and add both series to it.

    \snippet lineandbar/main.cpp 3

    To make the chart show the series properly, we have to create custom axes for the series. If we don't create custom axes, then each series will get scaled to
    use the maximum area of the chart (like in single series case) and the result will be incorrect. With custom axes we set the range of both series to follow the
    same axis. For the x-axis we use the QBarCategoryAxis and for the y-axis we use QValuesAxis.

    \snippet lineandbar/main.cpp 4

    And we also want to show the legend.

    \snippet lineandbar/main.cpp 5

    Finally we add the chart onto a view.

    \snippet lineandbar/main.cpp 6

    Now it is ready to be shown in a window.

    \snippet lineandbar/main.cpp 7
*/