@@ -1,34 +1,36 | |||||
1 | /*! |
|
1 | /*! | |
2 | \example examples/barchart |
|
2 | \example examples/barchart | |
3 | \title BarChart Example |
|
3 | \title BarChart Example | |
4 | \subtitle |
|
4 | \subtitle | |
5 |
|
5 | |||
6 | The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are drawn at the x-axis to the position defined by data. |
|
6 | The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are drawn at the x-axis to the position defined by data. | |
7 |
|
7 | |||
8 | \image examples_barchart.png |
|
8 | \image examples_barchart.png | |
9 |
|
9 | |||
10 | Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data |
|
10 | Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data | |
11 |
we want to visualize to them. Note that |
|
11 | we want to visualize to them. Note that x positions are not in even intervals and this will be reflected in the chart. | |
|
12 | If x positions aren't defined, then the index of value is assumed to be x position. | |||
12 |
|
13 | |||
13 | \snippet ../examples/barchart/main.cpp 1 |
|
14 | \snippet ../examples/barchart/main.cpp 1 | |
14 |
|
15 | |||
15 | To combine the sets to a chart, we need to create QBarSeries instance. Then we append our barsets to the series. |
|
16 | To combine the sets to a chart, we need to create QBarSeries instance. Then we append our barsets to the series. | |
16 |
|
17 | |||
17 | \snippet ../examples/barchart/main.cpp 2 |
|
18 | \snippet ../examples/barchart/main.cpp 2 | |
18 |
|
19 | |||
19 | Next we create a chart and add the series to it. |
|
20 | Next we create a chart and add the series to it. | |
|
21 | We also set the title for chart | |||
20 |
|
22 | |||
21 | \snippet ../examples/barchart/main.cpp 3 |
|
23 | \snippet ../examples/barchart/main.cpp 3 | |
22 |
|
24 | |||
23 | We want to have the legend displayed at the bottom of the chart. Also we turn on the nice numbers algorithm on for y-axis. |
|
25 | We want to have the legend displayed at the bottom of the chart. Also we turn on the nice numbers algorithm on for y-axis. | |
24 |
|
26 | |||
25 | \snippet ../examples/barchart/main.cpp 4 |
|
27 | \snippet ../examples/barchart/main.cpp 4 | |
26 |
|
28 | |||
27 | Finally we add the chart onto a view. |
|
29 | Finally we add the chart onto a view. | |
28 |
|
30 | |||
29 | \snippet ../examples/barchart/main.cpp 5 |
|
31 | \snippet ../examples/barchart/main.cpp 5 | |
30 |
|
32 | |||
31 | And it is ready to be shown in a window. |
|
33 | And it is ready to be shown in a window. | |
32 |
|
34 | |||
33 | \snippet ../examples/percentbarchart/main.cpp 6 |
|
35 | \snippet ../examples/percentbarchart/main.cpp 6 | |
34 | */ |
|
36 | */ |
@@ -1,40 +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 | First we define categories. |
|
10 | Data that groupedbarchart visualizes, is defined by QBarSet instances. Here we create the sets and append data | |
|
11 | to them. | |||
11 |
|
12 | |||
12 | \snippet ../examples/groupedbarchart/main.cpp 1 |
|
13 | \snippet ../examples/groupedbarchart/main.cpp 1 | |
13 |
|
14 | |||
14 | Data that groupedbarchart visualizes, is defined by QBarSet instances. Here we create some sets and append data |
|
15 | We create the series and append the sets to it. The grouped barseries groups the data from sets to categories. | |
15 | we want to visualize to them. |
|
16 | First value of each set are gropuped together at first category second value to second category and so on. | |
16 |
|
17 | |||
17 | \snippet ../examples/groupedbarchart/main.cpp 2 |
|
18 | \snippet ../examples/groupedbarchart/main.cpp 2 | |
18 |
|
19 | |||
19 | To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating |
|
20 | Then we create a chart and add the series to it. | |
20 | the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets |
|
|||
21 | are added to series here. |
|
|||
22 |
|
21 | |||
23 | \snippet ../examples/groupedbarchart/main.cpp 3 |
|
22 | \snippet ../examples/groupedbarchart/main.cpp 3 | |
24 |
|
23 | |||
25 | Then we create a chart and add the series to it. |
|
24 | We define the categories here and add them to the x-axis. | |
26 |
|
25 | |||
27 | \snippet ../examples/groupedbarchart/main.cpp 4 |
|
26 | \snippet ../examples/groupedbarchart/main.cpp 4 | |
28 |
|
27 | |||
29 | 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. | |
30 |
|
29 | |||
31 | \snippet ../examples/groupedbarchart/main.cpp 5 |
|
30 | \snippet ../examples/groupedbarchart/main.cpp 5 | |
32 |
|
31 | |||
33 | Finally we add the chart onto a view. |
|
32 | Finally we add the chart onto a view. | |
34 |
|
33 | |||
35 | \snippet ../examples/groupedbarchart/main.cpp 6 |
|
34 | \snippet ../examples/groupedbarchart/main.cpp 6 | |
36 |
|
35 | |||
37 | And it is ready to be shown in a window. |
|
36 | And it is ready to be shown in a window. | |
38 |
|
37 | |||
39 | \snippet ../examples/groupedbarchart/main.cpp 7 |
|
38 | \snippet ../examples/groupedbarchart/main.cpp 7 | |
40 | */ |
|
39 | */ |
@@ -1,80 +1,80 | |||||
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 <QBarSeries> |
|
24 | #include <QBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarSet *set0 = new QBarSet("Jane"); |
|
35 | QBarSet *set0 = new QBarSet("Jane"); | |
36 | QBarSet *set1 = new QBarSet("John"); |
|
36 | QBarSet *set1 = new QBarSet("John"); | |
37 | QBarSet *set2 = new QBarSet("Axel"); |
|
37 | QBarSet *set2 = new QBarSet("Axel"); | |
38 | QBarSet *set3 = new QBarSet("Mary"); |
|
38 | QBarSet *set3 = new QBarSet("Mary"); | |
39 |
|
39 | |||
40 | *set0 << QPointF(0.0, 1) << QPointF(1.0, 2) << QPointF(2.4, 3) << QPointF(3.0, 4) << QPointF(4.0, 5) << QPointF(5.0, 6); |
|
40 | *set0 << QPointF(0.0, 1) << QPointF(1.0, 2) << QPointF(2.4, 3) << QPointF(3.0, 4) << QPointF(4.0, 5) << QPointF(5.0, 6); | |
41 | *set1 << QPointF(0.1, 2) << QPointF(1.2, 3) << QPointF(2.45, 4) << QPointF(3.2, 5) << QPointF(4.2, 6) << QPointF(5.2, 7); |
|
41 | *set1 << QPointF(0.1, 2) << QPointF(1.2, 3) << QPointF(2.45, 4) << QPointF(3.2, 5) << QPointF(4.2, 6) << QPointF(5.2, 7); | |
42 | *set2 << QPointF(0.2, 3) << QPointF(1.4, 4) << QPointF(2.50, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8); |
|
42 | *set2 << QPointF(0.2, 3) << QPointF(1.4, 4) << QPointF(2.50, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8); | |
43 | *set3 << QPointF(0.3, 4) << QPointF(1.6, 5) << QPointF(2.55, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9); |
|
43 | *set3 << QPointF(0.3, 4) << QPointF(1.6, 5) << QPointF(2.55, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9); | |
44 | //![1] |
|
44 | //![1] | |
45 |
|
45 | |||
46 | //![2] |
|
46 | //![2] | |
47 | QBarSeries* series = new QBarSeries(); |
|
47 | QBarSeries* series = new QBarSeries(); | |
48 | series->setBarMargin(0.8); |
|
48 | series->setBarMargin(0.8); | |
49 | series->append(set0); |
|
49 | series->append(set0); | |
50 | series->append(set1); |
|
50 | series->append(set1); | |
51 | series->append(set2); |
|
51 | series->append(set2); | |
52 | series->append(set3); |
|
52 | series->append(set3); | |
53 | //![2] |
|
53 | //![2] | |
54 |
|
54 | |||
55 | //![3] |
|
55 | //![3] | |
56 | QChart* chart = new QChart(); |
|
56 | QChart* chart = new QChart(); | |
57 | chart->addSeries(series); |
|
57 | chart->addSeries(series); | |
58 |
chart->setTitle(" |
|
58 | chart->setTitle("Barchart example"); | |
59 | //![3] |
|
59 | //![3] | |
60 |
|
60 | |||
61 | //![4] |
|
61 | //![4] | |
62 | chart->legend()->setVisible(true); |
|
62 | chart->legend()->setVisible(true); | |
63 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
63 | chart->legend()->setAlignment(Qt::AlignBottom); | |
64 | chart->axisY()->setNiceNumbersEnabled(true); |
|
64 | chart->axisY()->setNiceNumbersEnabled(true); | |
65 | //![4] |
|
65 | //![4] | |
66 |
|
66 | |||
67 | //![5] |
|
67 | //![5] | |
68 | QChartView* chartView = new QChartView(chart); |
|
68 | QChartView* chartView = new QChartView(chart); | |
69 | chartView->setRenderHint(QPainter::Antialiasing); |
|
69 | chartView->setRenderHint(QPainter::Antialiasing); | |
70 | //![5] |
|
70 | //![5] | |
71 |
|
71 | |||
72 | //![6] |
|
72 | //![6] | |
73 | QMainWindow window; |
|
73 | QMainWindow window; | |
74 | window.setCentralWidget(chartView); |
|
74 | window.setCentralWidget(chartView); | |
75 | window.resize(400, 300); |
|
75 | window.resize(400, 300); | |
76 | window.show(); |
|
76 | window.show(); | |
77 | //![6] |
|
77 | //![6] | |
78 |
|
78 | |||
79 | return a.exec(); |
|
79 | return a.exec(); | |
80 | } |
|
80 | } |
@@ -1,90 +1,89 | |||||
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 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarSet *set0 = new QBarSet("Jane"); |
|
35 | QBarSet *set0 = new QBarSet("Jane"); | |
36 | QBarSet *set1 = new QBarSet("John"); |
|
36 | QBarSet *set1 = new QBarSet("John"); | |
37 | QBarSet *set2 = new QBarSet("Axel"); |
|
37 | QBarSet *set2 = new QBarSet("Axel"); | |
38 | QBarSet *set3 = new QBarSet("Mary"); |
|
38 | QBarSet *set3 = new QBarSet("Mary"); | |
39 | QBarSet *set4 = new QBarSet("Samantha"); |
|
39 | QBarSet *set4 = new QBarSet("Samantha"); | |
40 |
|
40 | |||
41 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
41 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
42 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
42 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
43 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
43 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
44 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
44 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
45 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
45 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
46 | //![1] |
|
46 | //![1] | |
47 |
|
47 | |||
48 | //![2] |
|
48 | //![2] | |
49 | QGroupedBarSeries* series = new QGroupedBarSeries(); |
|
49 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
50 | // series->setCategories(categories); |
|
|||
51 | series->append(set0); |
|
50 | series->append(set0); | |
52 | series->append(set1); |
|
51 | series->append(set1); | |
53 | series->append(set2); |
|
52 | series->append(set2); | |
54 | series->append(set3); |
|
53 | series->append(set3); | |
55 | series->append(set4); |
|
54 | series->append(set4); | |
56 |
|
55 | |||
57 | //![2] |
|
56 | //![2] | |
58 |
|
57 | |||
59 | //![3] |
|
58 | //![3] | |
60 | QChart* chart = new QChart(); |
|
59 | QChart* chart = new QChart(); | |
61 | chart->addSeries(series); |
|
60 | chart->addSeries(series); | |
62 | chart->setTitle("Simple grouped barchart example"); |
|
61 | chart->setTitle("Simple grouped barchart example"); | |
63 | //![3] |
|
62 | //![3] | |
64 |
|
63 | |||
65 | //![4] |
|
64 | //![4] | |
66 | QStringList categories; |
|
65 | QStringList categories; | |
67 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
66 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
68 | chart->axisX()->categories()->insert(categories); |
|
67 | chart->axisX()->categories()->insert(categories); | |
69 | //![4] |
|
68 | //![4] | |
70 |
|
69 | |||
71 | //![5] |
|
70 | //![5] | |
72 | chart->legend()->setVisible(true); |
|
71 | chart->legend()->setVisible(true); | |
73 | chart->legend()->setAlignment(Qt::AlignBottom); |
|
72 | chart->legend()->setAlignment(Qt::AlignBottom); | |
74 | chart->axisY()->setNiceNumbersEnabled(true); |
|
73 | chart->axisY()->setNiceNumbersEnabled(true); | |
75 | //![5] |
|
74 | //![5] | |
76 |
|
75 | |||
77 | //![6] |
|
76 | //![6] | |
78 | QChartView* chartView = new QChartView(chart); |
|
77 | QChartView* chartView = new QChartView(chart); | |
79 | chartView->setRenderHint(QPainter::Antialiasing); |
|
78 | chartView->setRenderHint(QPainter::Antialiasing); | |
80 | //![6] |
|
79 | //![6] | |
81 |
|
80 | |||
82 | //![7] |
|
81 | //![7] | |
83 | QMainWindow window; |
|
82 | QMainWindow window; | |
84 | window.setCentralWidget(chartView); |
|
83 | window.setCentralWidget(chartView); | |
85 | window.resize(400, 300); |
|
84 | window.resize(400, 300); | |
86 | window.show(); |
|
85 | window.show(); | |
87 | //![7] |
|
86 | //![7] | |
88 |
|
87 | |||
89 | return a.exec(); |
|
88 | return a.exec(); | |
90 | } |
|
89 | } |
General Comments 0
You need to be logged in to leave comments.
Login now