##// END OF EJS Templates
Updated bar chart documentation
Tero Ahola -
r971:29cedae3d4be
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: new file 100644, binary diff hidden
1 NO CONTENT: file renamed from doc/images/example_zoomlinechart1.png to doc/images/examples_zoomlinechart1.png
1 NO CONTENT: file renamed from doc/images/example_zoomlinechart2.png to doc/images/examples_zoomlinechart2.png
@@ -1,39 +1,40
1 1 /*!
2 2 \example examples/barchart
3 3 \title BarChart Example
4 4 \subtitle
5 5
6 6 The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are grouped in categories.
7 7
8 \image barchart.png
8 \image examples_barchart.png
9 9
10 10 First we define categories.
11 11
12 12 \snippet ../examples/barchart/main.cpp 1
13 13
14 14 Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data
15 we want to visulaize to them.
15 we want to visualize to them.
16 16
17 17 \snippet ../examples/barchart/main.cpp 2
18 18
19 19 To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating
20 20 the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets
21 21 are added to series here.
22 22
23 23 \snippet ../examples/barchart/main.cpp 3
24 24
25 We want our barchart to behave so, that when mouse is hovered over bar, the name of set which the bar
26 represents is shown as tooltip.
27 Also when we click the bar, floating values for the set are toggled. Floating values are the data values
28 that are drawn on top of bars.
29
25 Then we create a chart and add the series to it.
26
30 27 \snippet ../examples/barchart/main.cpp 4
31 28
32 Here we create the view and add our series to it. Also we set the title and theme we want our chart to use
33
29 And we also want to show the legend, so that the data is easier to read.
30
34 31 \snippet ../examples/barchart/main.cpp 5
35 32
36 For barchart, we don't need X-axis to be visible, so it can be disabled.
37
33 Finally we add the chart onto a view.
34
38 35 \snippet ../examples/barchart/main.cpp 6
39 */ No newline at end of file
36
37 And it is ready to be shown in a window.
38
39 \snippet ../examples/percentbarchart/main.cpp 7
40 */
@@ -1,39 +1,17
1 1 /*!
2 2 \example examples/percentbarchart
3 3 \title PercentBarChart Example
4 4 \subtitle
5 5
6 The example shows how to create simple percent bar chart. Percent bar chart shows the data in set as percentage of all sets, per category.
6 The example shows how to create simple percent bar chart. Percent bar chart shows the data in set as percentage of
7 all sets, per category.
7 8
8 \image percentbarchart.png
9
10 First we define categories.
9 \image examples_percentbarchart.png
11 10
12 \snippet ../examples/percentbarchart/main.cpp 1
13
14 Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data
15 we want to visulaize to them.
16
17 \snippet ../examples/percentbarchart/main.cpp 2
18
19 To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating
20 the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets
21 are added to series here.
11 Creating percent bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
12 percent bar chart, we use QPercentBarSeries api instead of QBarSeries. Also, in the
13 \l {BarChart Example} {bar chart} we used nice numbers algorithm to make the y axis numbering look better. With
14 percent bar chart there is no need for that, because the maximum y-axis value is always 100.
22 15
23 16 \snippet ../examples/percentbarchart/main.cpp 3
24
25 We want our barchart to behave so, that when mouse is hovered over bar, the name of set which the bar
26 represents is shown as tooltip.
27 Also when we click the bar, floating values for the set are toggled. Floating values are the data values
28 that are drawn on top of bars.
29
30 \snippet ../examples/percentbarchart/main.cpp 4
31
32 Here we create the view and add our series to it. Also we set the title and theme we want our chart to use
33
34 \snippet ../examples/percentbarchart/main.cpp 5
35
36 For barchart, we don't need X-axis to be visible, so it can be disabled.
37
38 \snippet ../examples/percentbarchart/main.cpp 6
39 */ No newline at end of file
17 */
@@ -1,39 +1,15
1 1 /*!
2 2 \example examples/stackedbarchart
3 3 \title StackedBarChart Example
4 4 \subtitle
5 5
6 The example shows how to create simple stacked bar chart. Stacked bar chart shows the data in sets as bars that are stacked on top of each other. The stacking is done per category.
6 The example shows how to create simple stacked bar chart. Stacked bar chart shows the data in sets as bars that are
7 stacked on top of each other. The stacking is done per category.
7 8
8 \image stackedbarchart.png
9 \image examples_stackedbarchart.png
9 10
10 First we define categories.
11
12 \snippet ../examples/stackedbarchart/main.cpp 1
13
14 Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data
15 we want to visulaize to them.
16
17 \snippet ../examples/stackedbarchart/main.cpp 2
18
19 To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating
20 the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets
21 are added to series here.
11 Creating stacked bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
12 stacked bar chart, we use QStackedBarSeries api instead of QBarSeries.
22 13
23 14 \snippet ../examples/stackedbarchart/main.cpp 3
24
25 We want our barchart to behave so, that when mouse is hovered over bar, the name of set which the bar
26 represents is shown as tooltip.
27 Also when we click the bar, floating values for the set are toggled. Floating values are the data values
28 that are drawn on top of bars.
29
30 \snippet ../examples/stackedbarchart/main.cpp 4
31
32 Here we create the view and add our series to it. Also we set the title and theme we want our chart to use
33
34 \snippet ../examples/stackedbarchart/main.cpp 5
35
36 For barchart, we don't need X-axis to be visible, so it can be disabled.
37
38 \snippet ../examples/stackedbarchart/main.cpp 6
39 */ No newline at end of file
15 */
@@ -1,22 +1,22
1 1 /*!
2 2 \example examples/zoomlinechart
3 3 \title Zoom line example
4 4 \subtitle
5 5
6 6 The example shows how to create your own custom zooming effect with QRubberBand.
7 \image example_zoomlinechart1.png
8 \image example_zoomlinechart2.png
7 \image examples_zoomlinechart1.png
8 \image examples_zoomlinechart2.png
9 9
10 10 Let's first create a line series with some example data.
11 11 \snippet ../examples/zoomlinechart/main.cpp 1
12 12
13 13 Then we create a custom chart view by deriving from QChartView:
14 14 \snippet ../examples/zoomlinechart/chartview.h 1
15 15
16 16 We override mouse and key event handling
17 17 \snippet ../examples/zoomlinechart/chartview.h 2
18 18
19 19 Then we implement a custom logic for mouse and key events. For example pressing '+' key will zoom in and pressing
20 20 the '-' key will zoom out.
21 21 \snippet ../examples/zoomlinechart/chartview.cpp 1
22 22 */
@@ -1,87 +1,87
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QPercentBarSeries>
25 25 #include <QBarSet>
26 26 #include <QLegend>
27 27
28 28 QTCOMMERCIALCHART_USE_NAMESPACE
29 29
30 30 int main(int argc, char *argv[])
31 31 {
32 32 QApplication a(argc, argv);
33 33
34 34 //![1]
35 35 QBarCategories categories;
36 36 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
37 37 //![1]
38 38
39 39 //![2]
40 40 QBarSet *set0 = new QBarSet("Jane");
41 41 QBarSet *set1 = new QBarSet("John");
42 42 QBarSet *set2 = new QBarSet("Axel");
43 43 QBarSet *set3 = new QBarSet("Mary");
44 44 QBarSet *set4 = new QBarSet("Samantha");
45 45
46 46 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
47 47 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
48 48 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
49 49 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
50 50 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
51 51 //![2]
52 52
53 53 //![3]
54 54 QPercentBarSeries* series = new QPercentBarSeries(categories);
55 55 series->appendBarSet(set0);
56 56 series->appendBarSet(set1);
57 57 series->appendBarSet(set2);
58 58 series->appendBarSet(set3);
59 59 series->appendBarSet(set4);
60 60 //![3]
61 61
62 62 //![4]
63 63 QChart* chart = new QChart();
64 64 chart->addSeries(series);
65 chart->setTitle("Simple precentbarchart example");
65 chart->setTitle("Simple percentbarchart example");
66 66 //![4]
67 67
68 68 //![5]
69 69 chart->legend()->setVisible(true);
70 70 chart->legend()->setAlignment(QLegend::AlignmentBottom);
71 71 //![5]
72 72
73 73 //![6]
74 74 QChartView* chartView = new QChartView(chart);
75 75 chartView->setRenderHint(QPainter::Antialiasing);
76 76 //![6]
77 77
78 78 //![7]
79 79 QMainWindow window;
80 80 window.setCentralWidget(chartView);
81 81 window.resize(400, 300);
82 82 window.show();
83 83 //![7]
84 84
85 85 return a.exec();
86 86 }
87 87
1 NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed, binary diff hidden
1 NO CONTENT: file was removed, binary diff hidden
General Comments 0
You need to be logged in to leave comments. Login now