@@ -1,39 +1,39 | |||||
1 | /*! |
|
1 | /*! | |
2 | \example examples/groupedbarchart |
|
2 | \example examples/groupedbarchart | |
3 | \title GroupedBarChart Example |
|
3 | \title GroupedBarChart Example | |
4 | \subtitle |
|
4 | \subtitle | |
5 |
|
5 | |||
6 | The example shows how to create simple bar chart. GroupedBarChart shows the data in sets as separate bars, which are grouped in categories. |
|
6 | The example shows how to create simple bar chart. GroupedBarChart shows the data in sets as separate bars, which are grouped in categories. | |
7 |
|
7 | |||
8 | \image examples_groupedbarchart.png |
|
8 | \image examples_groupedbarchart.png | |
9 |
|
9 | |||
10 | Data that groupedbarchart visualizes, is defined by QBarSet instances. Here we create the sets and append data |
|
10 | Data that groupedbarchart visualizes, is defined by QBarSet instances. Here we create the sets and append data | |
11 | to them. |
|
11 | to them. | |
12 |
|
12 | |||
13 | \snippet ../examples/groupedbarchart/main.cpp 1 |
|
13 | \snippet ../examples/groupedbarchart/main.cpp 1 | |
14 |
|
14 | |||
15 | We create the series and append the sets to it. The grouped barseries groups the data from sets to categories. |
|
15 | We create the series and append the sets to it. The grouped barseries groups the data from sets to categories. | |
16 | First value of each set are gropuped together at first category second value to second category and so on. |
|
16 | First value of each set are gropuped together at first category second value to second category and so on. | |
17 |
|
17 | |||
18 | \snippet ../examples/groupedbarchart/main.cpp 2 |
|
18 | \snippet ../examples/groupedbarchart/main.cpp 2 | |
19 |
|
19 | |||
20 | Then we create a chart and add the series to it. |
|
20 | Then we create a chart and add the series to it. | |
21 |
|
21 | |||
22 | \snippet ../examples/groupedbarchart/main.cpp 3 |
|
22 | \snippet ../examples/groupedbarchart/main.cpp 3 | |
23 |
|
23 | |||
24 | We define the categories here and add them to the x-axis. |
|
24 | We define the categories here and add them to QCategoriesAxis which we then set to be the x-axis of the chart. | |
25 |
|
25 | |||
26 | \snippet ../examples/groupedbarchart/main.cpp 4 |
|
26 | \snippet ../examples/groupedbarchart/main.cpp 4 | |
27 |
|
27 | |||
28 | And we also want to show the legend, so that the data is easier to read. |
|
28 | And we also want to show the legend, so that the data is easier to read. | |
29 |
|
29 | |||
30 | \snippet ../examples/groupedbarchart/main.cpp 5 |
|
30 | \snippet ../examples/groupedbarchart/main.cpp 5 | |
31 |
|
31 | |||
32 | Finally we add the chart onto a view. |
|
32 | Finally we add the chart onto a view. | |
33 |
|
33 | |||
34 | \snippet ../examples/groupedbarchart/main.cpp 6 |
|
34 | \snippet ../examples/groupedbarchart/main.cpp 6 | |
35 |
|
35 | |||
36 | And it is ready to be shown in a window. |
|
36 | And it is ready to be shown in a window. | |
37 |
|
37 | |||
38 | \snippet ../examples/groupedbarchart/main.cpp 7 |
|
38 | \snippet ../examples/groupedbarchart/main.cpp 7 | |
39 | */ |
|
39 | */ |
@@ -1,91 +1,92 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QGroupedBarSeries> |
|
24 | #include <QGroupedBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 | #include <QCategoriesAxis> |
|
27 | #include <QCategoriesAxis> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
32 | { |
|
32 | { | |
33 | QApplication a(argc, argv); |
|
33 | QApplication a(argc, argv); | |
34 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QBarSet *set0 = new QBarSet("Jane"); |
|
36 | QBarSet *set0 = new QBarSet("Jane"); | |
37 | QBarSet *set1 = new QBarSet("John"); |
|
37 | QBarSet *set1 = new QBarSet("John"); | |
38 | QBarSet *set2 = new QBarSet("Axel"); |
|
38 | QBarSet *set2 = new QBarSet("Axel"); | |
39 | QBarSet *set3 = new QBarSet("Mary"); |
|
39 | QBarSet *set3 = new QBarSet("Mary"); | |
40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
40 | QBarSet *set4 = new QBarSet("Samantha"); | |
41 |
|
41 | |||
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 | QGroupedBarSeries* series = new QGroupedBarSeries(); |
|
50 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
51 | series->append(set0); |
|
51 | series->append(set0); | |
52 | series->append(set1); |
|
52 | series->append(set1); | |
53 | series->append(set2); |
|
53 | series->append(set2); | |
54 | series->append(set3); |
|
54 | series->append(set3); | |
55 | series->append(set4); |
|
55 | series->append(set4); | |
56 |
|
56 | |||
57 | //![2] |
|
57 | //![2] | |
58 |
|
58 | |||
59 | //![3] |
|
59 | //![3] | |
60 | QChart* chart = new QChart(); |
|
60 | QChart* chart = new QChart(); | |
61 | chart->addSeries(series); |
|
61 | chart->addSeries(series); | |
62 | chart->setTitle("Simple grouped barchart example"); |
|
62 | chart->setTitle("Simple grouped barchart example"); | |
|
63 | chart->createDefaultAxes(); | |||
63 | //![3] |
|
64 | //![3] | |
64 |
|
65 | |||
65 | //![4] |
|
66 | //![4] | |
66 | QStringList categories; |
|
67 | QStringList categories; | |
67 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
68 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
68 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
69 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
69 | axis->append(categories); |
|
70 | axis->append(categories); | |
70 | chart->createDefaultAxes(); |
|
71 | chart->setAxisX(axis,series); | |
71 | //![4] |
|
72 | //![4] | |
72 |
|
73 | |||
73 | //![5] |
|
74 | //![5] | |
74 | chart->legend()->setVisible(true); |
|
75 | chart->legend()->setVisible(true); | |
75 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
76 | chart->legend()->setAlignment(Qt::AlignBottom); | |
76 | //![5] |
|
77 | //![5] | |
77 |
|
78 | |||
78 | //![6] |
|
79 | //![6] | |
79 | QChartView* chartView = new QChartView(chart); |
|
80 | QChartView* chartView = new QChartView(chart); | |
80 | chartView->setRenderHint(QPainter::Antialiasing); |
|
81 | chartView->setRenderHint(QPainter::Antialiasing); | |
81 | //![6] |
|
82 | //![6] | |
82 |
|
83 | |||
83 | //![7] |
|
84 | //![7] | |
84 | QMainWindow window; |
|
85 | QMainWindow window; | |
85 | window.setCentralWidget(chartView); |
|
86 | window.setCentralWidget(chartView); | |
86 | window.resize(400, 300); |
|
87 | window.resize(400, 300); | |
87 | window.show(); |
|
88 | window.show(); | |
88 | //![7] |
|
89 | //![7] | |
89 |
|
90 | |||
90 | return a.exec(); |
|
91 | return a.exec(); | |
91 | } |
|
92 | } |
@@ -1,91 +1,92 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QStackedBarSeries> |
|
24 | #include <QStackedBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 | #include <QCategoriesAxis> |
|
27 | #include <QCategoriesAxis> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
32 | { |
|
32 | { | |
33 | QApplication a(argc, argv); |
|
33 | QApplication a(argc, argv); | |
34 |
|
34 | |||
35 | //![1] |
|
35 | //![1] | |
36 | QBarSet *set0 = new QBarSet("Jane"); |
|
36 | QBarSet *set0 = new QBarSet("Jane"); | |
37 | QBarSet *set1 = new QBarSet("John"); |
|
37 | QBarSet *set1 = new QBarSet("John"); | |
38 | QBarSet *set2 = new QBarSet("Axel"); |
|
38 | QBarSet *set2 = new QBarSet("Axel"); | |
39 | QBarSet *set3 = new QBarSet("Mary"); |
|
39 | QBarSet *set3 = new QBarSet("Mary"); | |
40 | QBarSet *set4 = new QBarSet("Samantha"); |
|
40 | QBarSet *set4 = new QBarSet("Samantha"); | |
41 |
|
41 | |||
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
42 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
43 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
44 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
45 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
46 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
47 | //![1] |
|
47 | //![1] | |
48 |
|
48 | |||
49 | //![2] |
|
49 | //![2] | |
50 | QStackedBarSeries* series = new QStackedBarSeries(); |
|
50 | QStackedBarSeries* series = new QStackedBarSeries(); | |
51 | series->append(set0); |
|
51 | series->append(set0); | |
52 | series->append(set1); |
|
52 | series->append(set1); | |
53 | series->append(set2); |
|
53 | series->append(set2); | |
54 | series->append(set3); |
|
54 | series->append(set3); | |
55 | series->append(set4); |
|
55 | series->append(set4); | |
56 | //![2] |
|
56 | //![2] | |
57 |
|
57 | |||
58 | //![3] |
|
58 | //![3] | |
59 | QChart* chart = new QChart(); |
|
59 | QChart* chart = new QChart(); | |
60 | chart->addSeries(series); |
|
60 | chart->addSeries(series); | |
61 | chart->setTitle("Simple stackedbarchart example"); |
|
61 | chart->setTitle("Simple stackedbarchart example"); | |
|
62 | chart->createDefaultAxes(); | |||
62 | //![3] |
|
63 | //![3] | |
63 |
|
64 | |||
64 | //![4] |
|
65 | //![4] | |
65 | QStringList categories; |
|
66 | QStringList categories; | |
66 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
67 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
67 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
68 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
68 | axis->append(categories); |
|
69 | axis->append(categories); | |
69 | chart->setAxisX(axis,series); |
|
70 | chart->setAxisX(axis,series); | |
70 | //![4] |
|
71 | //![4] | |
71 |
|
72 | |||
72 | //![5] |
|
73 | //![5] | |
73 | chart->legend()->setVisible(true); |
|
74 | chart->legend()->setVisible(true); | |
74 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
75 | chart->legend()->setAlignment(Qt::AlignBottom); | |
75 | //![5] |
|
76 | //![5] | |
76 |
|
77 | |||
77 | //![6] |
|
78 | //![6] | |
78 | QChartView* chartView = new QChartView(chart); |
|
79 | QChartView* chartView = new QChartView(chart); | |
79 | chartView->setRenderHint(QPainter::Antialiasing); |
|
80 | chartView->setRenderHint(QPainter::Antialiasing); | |
80 | //![6] |
|
81 | //![6] | |
81 |
|
82 | |||
82 | //![7] |
|
83 | //![7] | |
83 | QMainWindow window; |
|
84 | QMainWindow window; | |
84 | window.setCentralWidget(chartView); |
|
85 | window.setCentralWidget(chartView); | |
85 | window.resize(400, 300); |
|
86 | window.resize(400, 300); | |
86 | window.show(); |
|
87 | window.show(); | |
87 | //![7] |
|
88 | //![7] | |
88 |
|
89 | |||
89 | return a.exec(); |
|
90 | return a.exec(); | |
90 | } |
|
91 | } | |
91 |
|
92 |
General Comments 0
You need to be logged in to leave comments.
Login now