##// END OF EJS Templates
Fix for typos on documentation.
Mika Salmela -
r2456:4278a56d8f51
parent child
Show More
@@ -1,47 +1,47
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 a bar chart. BarChart shows the data in sets as separate bars, which are in categories.
6 The example shows how to create a bar chart. BarChart shows the data in sets as separate bars, which are in categories.
7
7
8 \image examples_barchart.png
8 \image examples_barchart.png
9
9
10 The barsets are used in same way in all barcharts.
10 The barsets are used in same way in all barcharts.
11 To illustrate difference between various barcharts, we use same data in examples.
11 To illustrate difference between various barcharts, we use same data in examples.
12 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
12 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
13 to them. The data is appended here with << operator. Alternatively the append method could be used.
13 to them. The data is appended here with << operator. Alternatively the append method could be used.
14
14
15 \snippet ../examples/barchart/main.cpp 1
15 \snippet ../examples/barchart/main.cpp 1
16
16
17 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
17 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
18 First value of each set are gropuped together at first category second value to second category and so on.
18 First values of each set are grouped together at first category second value to second category and so on.
19
19
20 \snippet ../examples/barchart/main.cpp 2
20 \snippet ../examples/barchart/main.cpp 2
21
21
22 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
22 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
23 setAnimationOptions(QChart::SeriesAnimations)
23 setAnimationOptions(QChart::SeriesAnimations)
24
24
25 \snippet ../examples/barchart/main.cpp 3
25 \snippet ../examples/barchart/main.cpp 3
26
26
27 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
27 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
28 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
28 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
29 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
29 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
30 override the category axis.
30 override the category axis.
31
31
32 \snippet ../examples/barchart/main.cpp 4
32 \snippet ../examples/barchart/main.cpp 4
33
33
34 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment
34 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment
35 to Qt::AlignBottom.
35 to Qt::AlignBottom.
36
36
37 \snippet ../examples/barchart/main.cpp 5
37 \snippet ../examples/barchart/main.cpp 5
38
38
39 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
39 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
40
40
41 \snippet ../examples/barchart/main.cpp 6
41 \snippet ../examples/barchart/main.cpp 6
42
42
43 Chart is ready to be shown. We set the chart to be central widget of the window.
43 Chart is ready to be shown. We set the chart to be central widget of the window.
44 We also set the size for the chart window and show it.
44 We also set the size for the chart window and show it.
45
45
46 \snippet ../examples/barchart/main.cpp 7
46 \snippet ../examples/barchart/main.cpp 7
47 */
47 */
@@ -1,57 +1,57
1 /*!
1 /*!
2 \example examples/barmodelmapper
2 \example examples/barmodelmapper
3 \title BarModelMapper example
3 \title BarModelMapper example
4 \subtitle
4 \subtitle
5
5
6 This example shows how to use QAbstractItemModel derived model as the data for the bar series.
6 This example shows how to use QAbstractItemModel derived model as the data for the bar series.
7
7
8 \image examples_barmodelmapper.png
8 \image examples_barmodelmapper.png
9
9
10 Let's start by creating an instance of CustomTableModel class.
10 Let's start by creating an instance of CustomTableModel class.
11 CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example.
11 CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example.
12 The constructor of this class populates the internal data store of the model with the data that is good for our chart example.
12 The constructor of this class populates the internal data store of the model with the data that is good for our chart example.
13
13
14 \snippet ../examples/barmodelmapper/tablewidget.cpp 1
14 \snippet ../examples/barmodelmapper/tablewidget.cpp 1
15
15
16 We now have a model with data that we would like to display both on the chart and in a QTableView.
16 We now have a model with data that we would like to display both on the chart and in a QTableView.
17 First, we create QTableView and tell it use the model as a data source. To have the data presented nicely the minimum width of the table view is set and its headers resize mode changed to stretch.
17 First, we create QTableView and tell it use the model as a data source. To have the data presented nicely the minimum width of the table view is set and its headers resize mode changed to stretch.
18
18
19 \snippet ../examples/barmodelmapper/tablewidget.cpp 2
19 \snippet ../examples/barmodelmapper/tablewidget.cpp 2
20
20
21 Now we need QChart instance to display the same data on the chart.
21 Now we need QChart instance to display the same data on the chart.
22 We also enable animations. It makes it easier to see how modifying the model's data affect the chart.
22 We also enable animations. It makes it easier to see how modifying the model's data affect the chart.
23
23
24 \snippet ../examples/barmodelmapper/tablewidget.cpp 3
24 \snippet ../examples/barmodelmapper/tablewidget.cpp 3
25
25
26 First line of the code below creates new bar series. Variables firstRow and rowCount are used to define a custom model mapping.
26 First line of the code below creates new bar series. Variables firstRow and rowCount are used to define a custom model mapping.
27 Custom mapping allows to take only part of the data from the model. In this case data from 5 rows starting with the row with the index 3.
27 Custom mapping allows to take only part of the data from the model. In this case data from 5 rows starting with the row with the index 3.
28 Following three lines create an instance of QVBarModelMapper class and specifie that data for the bar sets should be taken from the model's columns with indexes from 1 to 4(inclusive).
28 Following three lines create an instance of QVBarModelMapper class and specifie that data for the bar sets should be taken from the model's columns with indexes from 1 to 4(inclusive).
29 To create a connection between the series and the model we set both of those objects to QVBarModelMapper.
29 To create a connection between the series and the model we set both of those objects to QVBarModelMapper.
30
30
31 Finally the series is added to the chart.
31 Finally the series is added to the chart.
32
32
33 \snippet ../examples/barmodelmapper/tablewidget.cpp 4
33 \snippet ../examples/barmodelmapper/tablewidget.cpp 4
34
34
35 To show in QTableView which data coresponds with which bar set this example uses table coloring.
35 To show in QTableView which data corresponds with which bar set this example uses table coloring.
36 When series is added to the chart it is assigned a color beased on the currently selected theme.
36 When series is added to the chart it is assigned a color based on the currently selected theme.
37 Code below extracts that color from the series and uses it to create colored QTableView.
37 Code below extracts that color from the series and uses it to create colored QTableView.
38 Coloring of the view is not a part of the QChart functionality.
38 Coloring of the view is not a part of the QChart functionality.
39
39
40 \snippet ../examples/barmodelmapper/tablewidget.cpp 5
40 \snippet ../examples/barmodelmapper/tablewidget.cpp 5
41
41
42 We would like to have categories placed on the chart's axis that describe what the data means.
42 We would like to have categories placed on the chart's axis that describe what the data means.
43 Next snippet shows how to do that.
43 Next snippet shows how to do that.
44
44
45 \snippet ../examples/barmodelmapper/tablewidget.cpp 6
45 \snippet ../examples/barmodelmapper/tablewidget.cpp 6
46
46
47 To avoid setting up the QGraphicsScene we use QChartView class that does it for us. QChart object pointer is used as a parameter of the QChartView constructor.
47 To avoid setting up the QGraphicsScene we use QChartView class that does it for us. QChart object pointer is used as a parameter of the QChartView constructor.
48 To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set.
48 To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set.
49
49
50 \snippet ../examples/barmodelmapper/tablewidget.cpp 7
50 \snippet ../examples/barmodelmapper/tablewidget.cpp 7
51
51
52 Finally we place both widgets in a layout and use the layout as the application layout.
52 Finally we place both widgets in a layout and use the layout as the application layout.
53
53
54 \snippet ../examples/barmodelmapper/tablewidget.cpp 8
54 \snippet ../examples/barmodelmapper/tablewidget.cpp 8
55
55
56 Application is ready. Try modifying the data in the table view and see how it affects the chart.
56 Application is ready. Try modifying the data in the table view and see how it affects the chart.
57 */
57 */
@@ -1,37 +1,37
1 /*!
1 /*!
2 \example examples/datetimeaxis
2 \example examples/datetimeaxis
3 \title DateTimeAxis Example
3 \title DateTimeAxis Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to use QLineChart with QDateTimeAxis.
6 The example shows how to use QLineChart with QDateTimeAxis.
7
7
8 \image examples_datetimeaxis.png
8 \image examples_datetimeaxis.png
9
9
10 To create line chart, QLineSeries instance is needed. Let's create one.
10 To create line chart, QLineSeries instance is needed. Let's create one.
11
11
12 \snippet ../examples/datetimeaxis/main.cpp 1
12 \snippet ../examples/datetimeaxis/main.cpp 1
13
13
14 On the charts we will present how the number of sun spots changes in time. The data (by Space Weather Prediction Center) is read from a text file.
14 On the charts we will present how the number of sun spots changes in time. The data (by Space Weather Prediction Center) is read from a text file.
15 In the snippet below notice how QDateTime::toMSecsSinceEpoch method is used to convert the QDateTime object into a number that can be passed to QLineSeries append method.
15 In the snippet below notice how QDateTime::toMSecsSinceEpoch method is used to convert the QDateTime object into a number that can be passed to QLineSeries append method.
16
16
17 \snippet ../examples/datetimeaxis/main.cpp 2
17 \snippet ../examples/datetimeaxis/main.cpp 2
18
18
19 To present the data on the char we need QChart instance. We add the series to it, hide the legend, create the default axes and set the title of the chart.
19 To present the data on the chart we need QChart instance. We add the series to it, hide the legend, create the default axes and set the title of the chart.
20
20
21 \snippet ../examples/datetimeaxis/main.cpp 3
21 \snippet ../examples/datetimeaxis/main.cpp 3
22
22
23 Becasue we use QLineSeries calling createDefaultAxes will create QValueAxis both as X and Y axis. To use QDateTimeAxis we need to set it manually to the chart.
23 Because we use QLineSeries calling createDefaultAxes will create QValueAxis both as X and Y axis. To use QDateTimeAxis we need to set it manually to the chart.
24 First the instance of QDateTimeAxis is created, then the number of ticks that are to be shown is set. The number of sun spots is provided as an average for the month therfore we don't need the axis labels to contain the information about the time and the day. This is achived by setting a custom label format.
24 First the instance of QDateTimeAxis is created, then the number of ticks that are to be shown is set. The number of sun spots is provided as an average for the month therefore we don't need the axis labels to contain the information about the time and the day. This is achieved by setting a custom label format.
25 Please refer to QDateTime::toString() method documntation to learn about the avaiable format options.
25 Please refer to QDateTime::toString() method documentation to learn about the available format options.
26
26
27 \snippet ../examples/datetimeaxis/main.cpp 4
27 \snippet ../examples/datetimeaxis/main.cpp 4
28
28
29 Then we create a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
29 Then we create a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
30
30
31 \snippet ../examples/datetimeaxis/main.cpp 5
31 \snippet ../examples/datetimeaxis/main.cpp 5
32
32
33 Chart is ready to be shown.
33 Chart is ready to be shown.
34
34
35 \snippet ../examples/datetimeaxis/main.cpp 6
35 \snippet ../examples/datetimeaxis/main.cpp 6
36
36
37 */
37 */
@@ -1,48 +1,48
1 /*!
1 /*!
2 \example examples/horizontalbarchart
2 \example examples/horizontalbarchart
3 \title HorizontalBarChart Example
3 \title HorizontalBarChart Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create a horizontal bar chart. QHorizontalBarChart shows the data in sets as separate bars, which are grouped in categories. QHorizontalBarChart works just like
6 The example shows how to create a horizontal bar chart. QHorizontalBarChart shows the data in sets as separate bars, which are grouped in categories. QHorizontalBarChart works just like
7 QBarChart, except that the bars are drawn horizontally on the chart.
7 QBarChart, except that the bars are drawn horizontally on the chart.
8
8
9 \image examples_horizontalbarchart.png
9 \image examples_horizontalbarchart.png
10
10
11 The barsets are used in same way in all barcharts.
11 The barsets are used in same way in all barcharts.
12 To illustrate difference between various barcharts, we use same data in examples.
12 To illustrate difference between various barcharts, we use same data in examples.
13 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
13 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
14 to them. The data is appended here with << operator. Alternatively the append method could be used.
14 to them. The data is appended here with << operator. Alternatively the append method could be used.
15
15
16 \snippet ../examples/horizontalbarchart/main.cpp 1
16 \snippet ../examples/horizontalbarchart/main.cpp 1
17
17
18 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
18 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
19 First value of each set are gropuped together at first category second value to second category and so on.
19 First value of each set are gropuped together at first category second value to second category and so on.
20
20
21 \snippet ../examples/horizontalbarchart/main.cpp 2
21 \snippet ../examples/horizontalbarchart/main.cpp 2
22
22
23 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
23 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
24 setAnimationOptions(QChart::SeriesAnimations)
24 setAnimationOptions(QChart::SeriesAnimations)
25
25
26 \snippet ../examples/horizontalbarchart/main.cpp 3
26 \snippet ../examples/horizontalbarchart/main.cpp 3
27
27
28 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
28 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
29 set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data
29 set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data
30 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
30 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
31 override the category axis.
31 override the category axis.
32
32
33 \snippet ../examples/horizontalbarchart/main.cpp 4
33 \snippet ../examples/horizontalbarchart/main.cpp 4
34
34
35 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment
35 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment
36 to Qt::AlignBottom.
36 to Qt::AlignBottom.
37
37
38 \snippet ../examples/horizontalbarchart/main.cpp 5
38 \snippet ../examples/horizontalbarchart/main.cpp 5
39
39
40 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
40 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
41
41
42 \snippet ../examples/horizontalbarchart/main.cpp 6
42 \snippet ../examples/horizontalbarchart/main.cpp 6
43
43
44 Chart is ready to be shown. We set the chart to be central widget of the window.
44 Chart is ready to be shown. We set the chart to be central widget of the window.
45 We also set the size for the chart window and show it.
45 We also set the size for the chart window and show it.
46
46
47 \snippet ../examples/horizontalbarchart/main.cpp 7
47 \snippet ../examples/horizontalbarchart/main.cpp 7
48 */
48 */
@@ -1,53 +1,53
1 /*!
1 /*!
2 \example examples/horizontalpercentbarchart
2 \example examples/horizontalpercentbarchart
3 \title HorizontalPercentBarChart Example
3 \title HorizontalPercentBarChart Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create simple horizontal percent bar chart. Horizontal percent bar chart shows the data in set as percentage of
6 The example shows how to create simple horizontal percent bar chart. Horizontal percent bar chart shows the data in set as percentage of
7 all sets, per category.
7 all sets, per category.
8
8
9 Creating horizontal percent bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
9 Creating horizontal percent bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
10 horizontal percent bar chart, we use QHorizontalPercentBarSeries api instead of QBarSeries. Also, in the
10 horizontal percent bar chart, we use QHorizontalPercentBarSeries api instead of QBarSeries. Also, in the
11 \l {BarChart Example} {bar chart} we used nice numbers algorithm to make the y axis numbering look better. With
11 \l {BarChart Example} {bar chart} we used nice numbers algorithm to make the y axis numbering look better. With
12 percent bar chart there is no need for that, because the maximum y-axis value is always 100.
12 percent bar chart there is no need for that, because the maximum y-axis value is always 100.
13
13
14 \image examples_horizontalpercentbarchart.png
14 \image examples_horizontalpercentbarchart.png
15
15
16 The barsets are used in same way in all barcharts.
16 The barsets are used in same way in all barcharts.
17 To illustrate difference between various barcharts, we use same data in examples.
17 To illustrate difference between various barcharts, we use same data in examples.
18 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
18 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
19 to them. The data is appended here with << operator. Alternatively the append method could be used.
19 to them. The data is appended here with << operator. Alternatively the append method could be used.
20
20
21 \snippet ../examples/horizontalpercentbarchart/main.cpp 1
21 \snippet ../examples/horizontalpercentbarchart/main.cpp 1
22
22
23 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
23 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
24 First value of each set are gropuped together at first category second value to second category and so on.
24 First values of each set are grouped together at first category second value to second category and so on.
25
25
26 \snippet ../examples/horizontalpercentbarchart/main.cpp 2
26 \snippet ../examples/horizontalpercentbarchart/main.cpp 2
27
27
28 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
28 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
29 setAnimationOptions(QChart::SeriesAnimations)
29 setAnimationOptions(QChart::SeriesAnimations)
30
30
31 \snippet ../examples/horizontalpercentbarchart/main.cpp 3
31 \snippet ../examples/horizontalpercentbarchart/main.cpp 3
32
32
33 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
33 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
34 set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data
34 set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data
35 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
35 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
36 override the category axis.
36 override the category axis.
37
37
38 \snippet ../examples/horizontalpercentbarchart/main.cpp 4
38 \snippet ../examples/horizontalpercentbarchart/main.cpp 4
39
39
40 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment
40 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment
41 to Qt::AlignBottom.
41 to Qt::AlignBottom.
42
42
43 \snippet ../examples/horizontalpercentbarchart/main.cpp 5
43 \snippet ../examples/horizontalpercentbarchart/main.cpp 5
44
44
45 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
45 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
46
46
47 \snippet ../examples/horizontalpercentbarchart/main.cpp 6
47 \snippet ../examples/horizontalpercentbarchart/main.cpp 6
48
48
49 Chart is ready to be shown. We set the chart to be central widget of the window.
49 Chart is ready to be shown. We set the chart to be central widget of the window.
50 We also set the size for the chart window and show it.
50 We also set the size for the chart window and show it.
51
51
52 \snippet ../examples/horizontalpercentbarchart/main.cpp 7
52 \snippet ../examples/horizontalpercentbarchart/main.cpp 7
53 */
53 */
@@ -1,50 +1,50
1 /*!
1 /*!
2 \example examples/horizontalstackedbarchart
2 \example examples/horizontalstackedbarchart
3 \title HorizontalStackedBarChart Example
3 \title HorizontalStackedBarChart Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create simple stacked horizontal bar chart. Stacked bar chart shows the data in sets as bars that are
6 The example shows how to create simple stacked horizontal 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 stacked on top of each other. The stacking is done per category.
8 Creating stacked horizontal bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
8 Creating stacked horizontal bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
9 stacked horizontal bar chart, we use QHorizontalStackedBarSeries api instead of QBarSeries.
9 stacked horizontal bar chart, we use QHorizontalStackedBarSeries api instead of QBarSeries.
10
10
11 \image examples_horizontalstackedbarchart.png
11 \image examples_horizontalstackedbarchart.png
12
12
13 The barsets are used in same way in all barcharts.
13 The barsets are used in same way in all barcharts.
14 To illustrate difference between various barcharts, we use same data in examples.
14 To illustrate difference between various barcharts, we use same data in examples.
15 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
15 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
16 to them. The data is appended here with << operator. Alternatively the append method could be used.
16 to them. The data is appended here with << operator. Alternatively the append method could be used.
17
17
18 \snippet ../examples/horizontalstackedbarchart/main.cpp 1
18 \snippet ../examples/horizontalstackedbarchart/main.cpp 1
19
19
20 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
20 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
21 First value of each set are gropuped together at first category second value to second category and so on.
21 First values of each set are grouped together at first category second value to second category and so on.
22
22
23 \snippet ../examples/horizontalstackedbarchart/main.cpp 2
23 \snippet ../examples/horizontalstackedbarchart/main.cpp 2
24
24
25 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
25 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
26 setAnimationOptions(QChart::SeriesAnimations)
26 setAnimationOptions(QChart::SeriesAnimations)
27
27
28 \snippet ../examples/horizontalstackedbarchart/main.cpp 3
28 \snippet ../examples/horizontalstackedbarchart/main.cpp 3
29
29
30 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
30 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
31 set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data
31 set it to be the y-axis of the chart. The chart takes ownership of axis. For x-axis we use default axis, which is created and scaled to series data
32 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
32 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
33 override the category axis.
33 override the category axis.
34
34
35 \snippet ../examples/horizontalstackedbarchart/main.cpp 4
35 \snippet ../examples/horizontalstackedbarchart/main.cpp 4
36
36
37 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment
37 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment
38 to Qt::AlignBottom.
38 to Qt::AlignBottom.
39
39
40 \snippet ../examples/horizontalstackedbarchart/main.cpp 5
40 \snippet ../examples/horizontalstackedbarchart/main.cpp 5
41
41
42 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
42 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
43
43
44 \snippet ../examples/horizontalstackedbarchart/main.cpp 6
44 \snippet ../examples/horizontalstackedbarchart/main.cpp 6
45
45
46 Chart is ready to be shown. We set the chart to be central widget of the window.
46 Chart is ready to be shown. We set the chart to be central widget of the window.
47 We also set the size for the chart window and show it.
47 We also set the size for the chart window and show it.
48
48
49 \snippet ../examples/horizontalstackedbarchart/main.cpp 7
49 \snippet ../examples/horizontalstackedbarchart/main.cpp 7
50 */
50 */
@@ -1,46 +1,46
1 /*!
1 /*!
2 \example examples/lineandbar
2 \example examples/lineandbar
3 \title Line and BarChart Example
3 \title Line and BarChart Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to combine different charts and set the axes. In the example we combine linechart with
6 The example shows how to combine different charts and set the axes. In the example we combine linechart with
7 barchart and use category axis as common axis for both.
7 barchart and use category axis as common axis for both.
8
8
9 \image examples_lineandbar.png
9 \image examples_lineandbar.png
10
10
11 Here we create data for our barseries.
11 Here we create data for our barseries.
12
12
13 \snippet ../examples/lineandbar/main.cpp 1
13 \snippet ../examples/lineandbar/main.cpp 1
14
14
15 We create the barseries and append the sets to it.
15 We create the barseries and append the sets to it.
16 First value of each set are gropuped together at first category second value to second category and so on.
16 First values of each set are grouped together at first category second value to second category and so on.
17
17
18 \snippet ../examples/lineandbar/main.cpp 2
18 \snippet ../examples/lineandbar/main.cpp 2
19
19
20 Then we create lineseries and add data to it. To make data match with barchart we use index as an x-value for our line series, so that
20 Then we create lineseries and add data to it. To make data match with barchart we use index as an x-value for our line series, so that
21 first point is at (0,value) second at (1,value) and so on.
21 first point is at (0,value) second at (1,value) and so on.
22
22
23 \snippet ../examples/lineandbar/main.cpp 8
23 \snippet ../examples/lineandbar/main.cpp 8
24
24
25 Here we create the chart and add both series to it.
25 Here we create the chart and add both series to it.
26
26
27 \snippet ../examples/lineandbar/main.cpp 3
27 \snippet ../examples/lineandbar/main.cpp 3
28
28
29 To make chart show series properly, we have to create custom axes for series. If we don't create custom axes, then each series will get scaled to
29 To make chart show series properly, we have to create custom axes for series. If we don't create custom axes, then each series will get scaled to
30 use maximum area of the chart (like in single series case) and result will be incorrect. With custom axes we set the range of both series to follow same
30 use maximum area of the chart (like in single series case) and result will be incorrect. With custom axes we set the range of both series to follow same
31 axis. For x-axis we use QBarCategoryAxis and for y-axis we use QValuesAxis.
31 axis. For x-axis we use QBarCategoryAxis and for y-axis we use QValuesAxis.
32
32
33 \snippet ../examples/lineandbar/main.cpp 4
33 \snippet ../examples/lineandbar/main.cpp 4
34
34
35 And we also want to show the legend.
35 And we also want to show the legend.
36
36
37 \snippet ../examples/lineandbar/main.cpp 5
37 \snippet ../examples/lineandbar/main.cpp 5
38
38
39 Finally we add the chart onto a view.
39 Finally we add the chart onto a view.
40
40
41 \snippet ../examples/lineandbar/main.cpp 6
41 \snippet ../examples/lineandbar/main.cpp 6
42
42
43 And it is ready to be shown in a window.
43 And it is ready to be shown in a window.
44
44
45 \snippet ../examples/lineandbar/main.cpp 7
45 \snippet ../examples/lineandbar/main.cpp 7
46 */
46 */
@@ -1,30 +1,30
1 /*!
1 /*!
2 \example examples/linechart
2 \example examples/linechart
3 \title LineChart Example
3 \title LineChart Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create simple line chart.
6 The example shows how to create simple line chart.
7
7
8 \image examples_linechart.png
8 \image examples_linechart.png
9
9
10 To create line chart, QLineSeries instance is needed. Let's create one.
10 To create line chart, QLineSeries instance is needed. Let's create one.
11
11
12 \snippet ../examples/linechart/main.cpp 1
12 \snippet ../examples/linechart/main.cpp 1
13
13
14 Then we add data to series. We can use append() member function or use stream operator.
14 Then we add data to series. We can use append() member function or use stream operator.
15
15
16 \snippet ../examples/linechart/main.cpp 2
16 \snippet ../examples/linechart/main.cpp 2
17
17
18 To present the data on the char we need QChart instance. We add the series to it, create the default axes and set the title of the chart.
18 To present the data on the chart we need QChart instance. We add the series to it, create the default axes and set the title of the chart.
19
19
20 \snippet ../examples/linechart/main.cpp 3
20 \snippet ../examples/linechart/main.cpp 3
21
21
22 Then we create a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
22 Then we create a QChartView object with QChart as a parameter. This way we don't need to create QGraphicsView scene ourselves. We also set the Antialiasing on to have the rendered lines look nicer.
23
23
24 \snippet ../examples/linechart/main.cpp 4
24 \snippet ../examples/linechart/main.cpp 4
25
25
26 Chart is ready to be shown.
26 Chart is ready to be shown.
27
27
28 \snippet ../examples/linechart/main.cpp 5
28 \snippet ../examples/linechart/main.cpp 5
29
29
30 */
30 */
@@ -1,30 +1,30
1 /*!
1 /*!
2 \example examples/logvalueaxis
2 \example examples/logvalueaxis
3 \title Logarithmic axis example
3 \title Logarithmic axis example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to use QLogValueAxis.
6 The example shows how to use QLogValueAxis.
7
7
8 \image examples_logvalueaxis.png
8 \image examples_logvalueaxis.png
9
9
10 Create QLineSeries instance and add some data to it.
10 Create QLineSeries instance and add some data to it.
11
11
12 \snippet ../examples/logvalueaxis/main.cpp 1
12 \snippet ../examples/logvalueaxis/main.cpp 1
13
13
14 To present the data on the char we need QChart instance. Add the series to it, hide the legend and set the title of the chart.
14 To present the data on the chart we need QChart instance. Add the series to it, hide the legend and set the title of the chart.
15
15
16 \snippet ../examples/logvalueaxis/main.cpp 2
16 \snippet ../examples/logvalueaxis/main.cpp 2
17
17
18 Create the axes. Add them to the chart and attach to the series.
18 Create the axes. Add them to the chart and attach to the series.
19
19
20 \snippet ../examples/logvalueaxis/main.cpp 3
20 \snippet ../examples/logvalueaxis/main.cpp 3
21
21
22 Then create a QChartView object with QChart as a parameter. Enable antialiasing to have the rendered line look nicer.
22 Then create a QChartView object with QChart as a parameter. Enable antialiasing to have the rendered line look nicer.
23
23
24 \snippet ../examples/logvalueaxis/main.cpp 4
24 \snippet ../examples/logvalueaxis/main.cpp 4
25
25
26 Chart is ready to be shown.
26 Chart is ready to be shown.
27
27
28 \snippet ../examples/logvalueaxis/main.cpp 5
28 \snippet ../examples/logvalueaxis/main.cpp 5
29
29
30 */
30 */
@@ -1,57 +1,57
1 /*!
1 /*!
2 \example examples/modeldata
2 \example examples/modeldata
3 \title Model data example
3 \title Model data example
4 \subtitle
4 \subtitle
5
5
6 This example shows how to use QAbstractItemModel derived model as the data for the series.
6 This example shows how to use QAbstractItemModel derived model as the data for the series.
7
7
8 \image examples_modeldata.png
8 \image examples_modeldata.png
9
9
10 Let's start by creating an instance of CustomTableModel class.
10 Let's start by creating an instance of CustomTableModel class.
11 CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example.
11 CustomTableModel class is derived from QAbstractTableModel and it was created for the purpose of this example.
12 The constructor of this class populates the internal data store of the model with the data that is good for our chart example.
12 The constructor of this class populates the internal data store of the model with the data that is good for our chart example.
13
13
14 \snippet ../examples/modeldata/tablewidget.cpp 1
14 \snippet ../examples/modeldata/tablewidget.cpp 1
15
15
16 We now have a model with data that we would like to display both on the chart and in a QTableView.
16 We now have a model with data that we would like to display both on the chart and in a QTableView.
17 First, we create QTableView and tell it use the model as a data source. To make the data cells fill the table view we also change headers resize mode.
17 First, we create QTableView and tell it use the model as a data source. To make the data cells fill the table view we also change headers resize mode.
18
18
19 \snippet ../examples/modeldata/tablewidget.cpp 2
19 \snippet ../examples/modeldata/tablewidget.cpp 2
20
20
21 Now we need QChart instance to display the same data on the chart.
21 Now we need QChart instance to display the same data on the chart.
22 We also enable animations. It makes it easier to see how modifying the model's data affect the chart.
22 We also enable animations. It makes it easier to see how modifying the model's data affect the chart.
23
23
24 \snippet ../examples/modeldata/tablewidget.cpp 3
24 \snippet ../examples/modeldata/tablewidget.cpp 3
25
25
26 The code below creates new line series and gives it a name. Following line creates an instance of QVXYModelMapper class.
26 The code below creates new line series and gives it a name. Following line creates an instance of QVXYModelMapper class.
27 Next two lines specifie that x coordinates are taken from the model's column(Qt::Vertical) with index 0 and the y coordinates are taken from the model's column with index 1.
27 Next two lines specifie that x coordinates are taken from the model's column(Qt::Vertical) with index 0 and the y coordinates are taken from the model's column with index 1.
28 To create a connection between the series and the model we set both of those objects to QVXYModelMapper.
28 To create a connection between the series and the model we set both of those objects to QVXYModelMapper.
29
29
30 Finally the series is added to the chart.
30 Finally the series is added to the chart.
31
31
32 \snippet ../examples/modeldata/tablewidget.cpp 4
32 \snippet ../examples/modeldata/tablewidget.cpp 4
33
33
34 To show in QTableView which data coresponds with which series this example uses table coloring.
34 To show in QTableView which data corresponds with which series this example uses table coloring.
35 When series is added to the chart it is assigned a color based on the currently selected theme.
35 When series is added to the chart it is assigned a color based on the currently selected theme.
36 Code below extracts that color from the series and uses it to create colored QTableView.
36 Code below extracts that color from the series and uses it to create colored QTableView.
37 Coloring of the view is not a part of the QChart functionality.
37 Coloring of the view is not a part of the QChart functionality.
38
38
39 \snippet ../examples/modeldata/tablewidget.cpp 5
39 \snippet ../examples/modeldata/tablewidget.cpp 5
40
40
41 The same operations are done with second series. Notice that for this series different columns of the same model are mapped.
41 The same operations are done with second series. Notice that for this series different columns of the same model are mapped.
42
42
43 \snippet ../examples/modeldata/tablewidget.cpp 6
43 \snippet ../examples/modeldata/tablewidget.cpp 6
44
44
45 \snippet ../examples/modeldata/tablewidget.cpp 7
45 \snippet ../examples/modeldata/tablewidget.cpp 7
46
46
47 To avoid setting up the QGraphicsScene we use QChartView class that does it for us. QChart object pointer is used as a parameter of the QChartView constructor.
47 To avoid setting up the QGraphicsScene we use QChartView class that does it for us. QChart object pointer is used as a parameter of the QChartView constructor.
48 To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set.
48 To make the render look nicer Antialiasing is turned on and the minimum size of the chartView widget is set.
49
49
50 \snippet ../examples/modeldata/tablewidget.cpp 8
50 \snippet ../examples/modeldata/tablewidget.cpp 8
51
51
52 Finally we place both widgets in a layout and use the layout as the application layout.
52 Finally we place both widgets in a layout and use the layout as the application layout.
53
53
54 \snippet ../examples/modeldata/tablewidget.cpp 9
54 \snippet ../examples/modeldata/tablewidget.cpp 9
55
55
56 Application is ready. Try modifying the data in the table view and see how it affects the chart.
56 Application is ready. Try modifying the data in the table view and see how it affects the chart.
57 */
57 */
@@ -1,53 +1,53
1 /*!
1 /*!
2 \example examples/percentbarchart
2 \example examples/percentbarchart
3 \title PercentBarChart Example
3 \title PercentBarChart Example
4 \subtitle
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
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 all sets, per category.
8
8
9 Creating percent bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
9 Creating percent bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
10 percent bar chart, we use QPercentBarSeries api instead of QBarSeries. Also, in the
10 percent bar chart, we use QPercentBarSeries api instead of QBarSeries. Also, in the
11 \l {BarChart Example} {bar chart} we used nice numbers algorithm to make the y axis numbering look better. With
11 \l {BarChart Example} {bar chart} we used nice numbers algorithm to make the y axis numbering look better. With
12 percent bar chart there is no need for that, because the maximum y-axis value is always 100.
12 percent bar chart there is no need for that, because the maximum y-axis value is always 100.
13
13
14 \image examples_percentbarchart.png
14 \image examples_percentbarchart.png
15
15
16 The barsets are used in same way in all barcharts.
16 The barsets are used in same way in all barcharts.
17 To illustrate difference between various barcharts, we use same data in examples.
17 To illustrate difference between various barcharts, we use same data in examples.
18 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
18 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
19 to them. The data is appended here with << operator. Alternatively the append method could be used.
19 to them. The data is appended here with << operator. Alternatively the append method could be used.
20
20
21 \snippet ../examples/percentbarchart/main.cpp 1
21 \snippet ../examples/percentbarchart/main.cpp 1
22
22
23 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
23 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
24 First value of each set are gropuped together at first category second value to second category and so on.
24 First values of each set are grouped together at first category second value to second category and so on.
25
25
26 \snippet ../examples/percentbarchart/main.cpp 2
26 \snippet ../examples/percentbarchart/main.cpp 2
27
27
28 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
28 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
29 setAnimationOptions(QChart::SeriesAnimations)
29 setAnimationOptions(QChart::SeriesAnimations)
30
30
31 \snippet ../examples/percentbarchart/main.cpp 3
31 \snippet ../examples/percentbarchart/main.cpp 3
32
32
33 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
33 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
34 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
34 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
35 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
35 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
36 override the category axis.
36 override the category axis.
37
37
38 \snippet ../examples/percentbarchart/main.cpp 4
38 \snippet ../examples/percentbarchart/main.cpp 4
39
39
40 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment
40 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment
41 to Qt::AlignBottom.
41 to Qt::AlignBottom.
42
42
43 \snippet ../examples/percentbarchart/main.cpp 5
43 \snippet ../examples/percentbarchart/main.cpp 5
44
44
45 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
45 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
46
46
47 \snippet ../examples/percentbarchart/main.cpp 6
47 \snippet ../examples/percentbarchart/main.cpp 6
48
48
49 Chart is ready to be shown. We set the chart to be central widget of the window.
49 Chart is ready to be shown. We set the chart to be central widget of the window.
50 We also set the size for the chart window and show it.
50 We also set the size for the chart window and show it.
51
51
52 \snippet ../examples/percentbarchart/main.cpp 7
52 \snippet ../examples/percentbarchart/main.cpp 7
53 */
53 */
@@ -1,54 +1,54
1 /*!
1 /*!
2 \example examples/stackedbarchart
2 \example examples/stackedbarchart
3 \title StackedBarChart Example
3 \title StackedBarChart Example
4 \subtitle
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
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 stacked on top of each other. The stacking is done per category.
8 The example shows how to create simple stacked bar chart. Stacked bar chart shows the data in sets as bars that are
8 The example shows how to create simple stacked bar chart. Stacked bar chart shows the data in sets as bars that are
9 stacked on top of each other. The stacking is done per category.
9 stacked on top of each other. The stacking is done per category.
10 Creating stacked bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
10 Creating stacked bar chart is just like creating a regular \l {BarChart Example} {bar chart}, except that for a
11 stacked bar chart, we use QStackedBarSeries api instead of QBarSeries.
11 stacked bar chart, we use QStackedBarSeries api instead of QBarSeries.
12
12
13 \image examples_stackedbarchart.png
13 \image examples_stackedbarchart.png
14
14
15 The barsets are used in same way in all barcharts.
15 The barsets are used in same way in all barcharts.
16 To illustrate difference between various barcharts, we use same data in examples.
16 To illustrate difference between various barcharts, we use same data in examples.
17 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
17 Data that barchart visualizes, is defined by QBarSet instances. Here we create the sets and append data
18 to them. The data is appended here with << operator. Alternatively the append method could be used.
18 to them. The data is appended here with << operator. Alternatively the append method could be used.
19
19
20 \snippet ../examples/stackedbarchart/main.cpp 1
20 \snippet ../examples/stackedbarchart/main.cpp 1
21
21
22 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
22 We create the series and append the barsets to it. The series takes ownership of the barsets. The series groups the data from sets to categories.
23 First value of each set are gropuped together at first category second value to second category and so on.
23 First values of each set are grouped together at first category second value to second category and so on.
24
24
25 \snippet ../examples/stackedbarchart/main.cpp 2
25 \snippet ../examples/stackedbarchart/main.cpp 2
26
26
27 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
27 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
28 setAnimationOptions(QChart::SeriesAnimations)
28 setAnimationOptions(QChart::SeriesAnimations)
29
29
30 \snippet ../examples/stackedbarchart/main.cpp 3
30 \snippet ../examples/stackedbarchart/main.cpp 3
31
31
32 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
32 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
33 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
33 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
34 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
34 by calling createDefaultAxes of the chart. Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will
35 override the category axis.
35 override the category axis.
36
36
37 \snippet ../examples/stackedbarchart/main.cpp 4
37 \snippet ../examples/stackedbarchart/main.cpp 4
38
38
39 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment
39 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment
40 to Qt::AlignBottom.
40 to Qt::AlignBottom.
41
41
42 \snippet ../examples/stackedbarchart/main.cpp 5
42 \snippet ../examples/stackedbarchart/main.cpp 5
43
43
44 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
44 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
45
45
46 \snippet ../examples/stackedbarchart/main.cpp 6
46 \snippet ../examples/stackedbarchart/main.cpp 6
47
47
48 Chart is ready to be shown. We set the chart to be central widget of the window.
48 Chart is ready to be shown. We set the chart to be central widget of the window.
49 We also set the size for the chart window and show it.
49 We also set the size for the chart window and show it.
50
50
51 \snippet ../examples/stackedbarchart/main.cpp 7
51 \snippet ../examples/stackedbarchart/main.cpp 7
52 */
52 */
53
53
54
54
@@ -1,44 +1,44
1 /*!
1 /*!
2 \example examples/temperaturerecords
2 \example examples/temperaturerecords
3 \title Temperature records example
3 \title Temperature records example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create a bar chart with negative bars. For example purposes we use temperature data.
6 The example shows how to create a bar chart with negative bars. For example purposes we use temperature data.
7
7
8 \image examples_temperaturerecords.png
8 \image examples_temperaturerecords.png
9
9
10 First we create two barsets and append the data to them. One set represents the minimum temperatures and another maximum temperatures.
10 First we create two barsets and append the data to them. One set represents the minimum temperatures and another maximum temperatures.
11
11
12 \snippet ../examples/temperaturerecords/main.cpp 1
12 \snippet ../examples/temperaturerecords/main.cpp 1
13
13
14 We create the series and append the barsets to it. The series takes ownership of the barsets.
14 We create the series and append the barsets to it. The series takes ownership of the barsets.
15
15
16 \snippet ../examples/temperaturerecords/main.cpp 2
16 \snippet ../examples/temperaturerecords/main.cpp 2
17
17
18 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
18 Here we create the chart object and add the series to it. We set the title for chart with setTitle and then turn on animations of the series by calling
19 setAnimationOptions(QChart::SeriesAnimations)
19 setAnimationOptions(QChart::SeriesAnimations)
20
20
21 \snippet ../examples/temperaturerecords/main.cpp 3
21 \snippet ../examples/temperaturerecords/main.cpp 3
22
22
23 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
23 To have categories displayed on axis, we need to create a QBarCategoryAxis for that. Here we create a category axis with list of categories and
24 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
24 set it to be the x-axis of the chart. The chart takes ownership of axis. For y-axis we use default axis, which is created and scaled to series data
25 by calling createDefaultAxes of the chart. We change the range for y-axis, since in this case it gives nicer result than autoscaling.
25 by calling createDefaultAxes of the chart. We change the range for y-axis, since in this case it gives nicer result than autoscaling.
26
26
27 Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will override the category axis.
27 Note that the call for createDefaultAxes must be before we set the category axis. Otherwise the default axis will override the category axis.
28
28
29 \snippet ../examples/temperaturerecords/main.cpp 4
29 \snippet ../examples/temperaturerecords/main.cpp 4
30
30
31 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting it's alignment
31 We also want to show the legend. To do that, we get the legend pointer from chart and set it to visible. We also place the legend to bottom of the chart by setting its alignment
32 to Qt::AlignBottom.
32 to Qt::AlignBottom.
33
33
34 \snippet ../examples/temperaturerecords/main.cpp 5
34 \snippet ../examples/temperaturerecords/main.cpp 5
35
35
36 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
36 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
37
37
38 \snippet ../examples/temperaturerecords/main.cpp 6
38 \snippet ../examples/temperaturerecords/main.cpp 6
39
39
40 Chart is ready to be shown. We set the chart to be central widget of the window.
40 Chart is ready to be shown. We set the chart to be central widget of the window.
41 We also set the size for the chart window and show it.
41 We also set the size for the chart window and show it.
42
42
43 \snippet ../examples/temperaturerecords/main.cpp 7
43 \snippet ../examples/temperaturerecords/main.cpp 7
44 */
44 */
@@ -1,654 +1,654
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include "chartlayout_p.h"
27 #include "chartlayout_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartpresenter_p.h"
29 #include "chartpresenter_p.h"
30 #include "chartdataset_p.h"
30 #include "chartdataset_p.h"
31 #include <QGraphicsScene>
31 #include <QGraphicsScene>
32 #include <QGraphicsSceneResizeEvent>
32 #include <QGraphicsSceneResizeEvent>
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 /*!
36 /*!
37 \enum QChart::ChartTheme
37 \enum QChart::ChartTheme
38
38
39 This enum describes the theme used by the chart.
39 This enum describes the theme used by the chart.
40
40
41 \value ChartThemeLight The default theme
41 \value ChartThemeLight The default theme
42 \value ChartThemeBlueCerulean
42 \value ChartThemeBlueCerulean
43 \value ChartThemeDark
43 \value ChartThemeDark
44 \value ChartThemeBrownSand
44 \value ChartThemeBrownSand
45 \value ChartThemeBlueNcs
45 \value ChartThemeBlueNcs
46 \value ChartThemeHighContrast
46 \value ChartThemeHighContrast
47 \value ChartThemeBlueIcy
47 \value ChartThemeBlueIcy
48 */
48 */
49
49
50 /*!
50 /*!
51 \enum QChart::AnimationOption
51 \enum QChart::AnimationOption
52
52
53 For enabling/disabling animations. Defaults to NoAnimation.
53 For enabling/disabling animations. Defaults to NoAnimation.
54
54
55 \value NoAnimation
55 \value NoAnimation
56 \value GridAxisAnimations
56 \value GridAxisAnimations
57 \value SeriesAnimations
57 \value SeriesAnimations
58 \value AllAnimations
58 \value AllAnimations
59 */
59 */
60
60
61 /*!
61 /*!
62 \class QChart
62 \class QChart
63 \brief QtCommercial chart API.
63 \brief QtCommercial chart API.
64
64
65 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
65 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
66 representation of different types of series and other chart related objects like
66 representation of different types of series and other chart related objects like
67 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
67 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
68 convenience class QChartView instead of QChart.
68 convenience class QChartView instead of QChart.
69 \sa QChartView
69 \sa QChartView
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QChart::animationOptions
73 \property QChart::animationOptions
74 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
74 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
75 */
75 */
76
76
77 /*!
77 /*!
78 \property QChart::backgroundVisible
78 \property QChart::backgroundVisible
79 Whether the chart background is visible or not.
79 Whether the chart background is visible or not.
80 \sa setBackgroundBrush(), setBackgroundPen()
80 \sa setBackgroundBrush(), setBackgroundPen()
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QChart::dropShadowEnabled
84 \property QChart::dropShadowEnabled
85 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
85 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
86 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
86 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
87 */
87 */
88
88
89 /*!
89 /*!
90 \property QChart::minimumMargins
90 \property QChart::minimumMargins
91 Minimum margins between the plot area (axes) and the edge of the chart widget.
91 Minimum margins between the plot area (axes) and the edge of the chart widget.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QChart::margins
95 \property QChart::margins
96 Minimum between the plot area (axes) and the edge of the chart widget.
96 Minimum between the plot area (axes) and the edge of the chart widget.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QChart::theme
100 \property QChart::theme
101 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
101 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
102 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
102 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
103 different themes.
103 different themes.
104 Note: changing the theme will overwrite all customizations previously applied to the series.
104 Note: changing the theme will overwrite all customizations previously applied to the series.
105 */
105 */
106
106
107 /*!
107 /*!
108 \property QChart::title
108 \property QChart::title
109 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
109 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
110 */
110 */
111
111
112 /*!
112 /*!
113 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
113 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
114 */
114 */
115 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
115 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
116 : QGraphicsWidget(parent, wFlags),
116 : QGraphicsWidget(parent, wFlags),
117 d_ptr(new QChartPrivate(this))
117 d_ptr(new QChartPrivate(this))
118 {
118 {
119 d_ptr->m_legend = new LegendScroller(this);
119 d_ptr->m_legend = new LegendScroller(this);
120 setTheme(QChart::ChartThemeLight);
120 setTheme(QChart::ChartThemeLight);
121 setLayout(d_ptr->m_presenter->layout());
121 setLayout(d_ptr->m_presenter->layout());
122 }
122 }
123
123
124 /*!
124 /*!
125 Destroys the object and it's children, like series and axis objects added to it.
125 Destroys the object and it's children, like series and axis objects added to it.
126 */
126 */
127 QChart::~QChart()
127 QChart::~QChart()
128 {
128 {
129 //start by deleting dataset, it will remove all series and axes
129 //start by deleting dataset, it will remove all series and axes
130 delete d_ptr->m_dataset;
130 delete d_ptr->m_dataset;
131 d_ptr->m_dataset = 0;
131 d_ptr->m_dataset = 0;
132 }
132 }
133
133
134 /*!
134 /*!
135 Adds the \a series onto the chart and takes the ownership of the object.
135 Adds the \a series onto the chart and takes the ownership of the object.
136 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
136 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
137 the y axis).
137 the y axis).
138
138
139 \sa removeSeries(), removeAllSeries()
139 \sa removeSeries(), removeAllSeries()
140 */
140 */
141 void QChart::addSeries(QAbstractSeries *series)
141 void QChart::addSeries(QAbstractSeries *series)
142 {
142 {
143 Q_ASSERT(series);
143 Q_ASSERT(series);
144 d_ptr->m_dataset->addSeries(series);
144 d_ptr->m_dataset->addSeries(series);
145 }
145 }
146
146
147 /*!
147 /*!
148 Removes the \a series specified in a perameter from the QChartView.
148 Removes the \a series specified in a perameter from the QChartView.
149 It releses its ownership of the specified QChartSeries object.
149 It releses its ownership of the specified QChartSeries object.
150 It does not delete the pointed QChartSeries data object
150 It does not delete the pointed QChartSeries data object
151 \sa addSeries(), removeAllSeries()
151 \sa addSeries(), removeAllSeries()
152 */
152 */
153 void QChart::removeSeries(QAbstractSeries *series)
153 void QChart::removeSeries(QAbstractSeries *series)
154 {
154 {
155 Q_ASSERT(series);
155 Q_ASSERT(series);
156 d_ptr->m_dataset->removeSeries(series);
156 d_ptr->m_dataset->removeSeries(series);
157 }
157 }
158
158
159 /*!
159 /*!
160 Removes all the QChartSeries that have been added to the QChartView
160 Removes all the QChartSeries that have been added to the QChartView
161 It also deletes the pointed QChartSeries data objects
161 It also deletes the pointed QChartSeries data objects
162 \sa addSeries(), removeSeries()
162 \sa addSeries(), removeSeries()
163 */
163 */
164 void QChart::removeAllSeries()
164 void QChart::removeAllSeries()
165 {
165 {
166 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
166 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
167 removeSeries(s);
167 removeSeries(s);
168 delete s;
168 delete s;
169 }
169 }
170 }
170 }
171
171
172 /*!
172 /*!
173 Sets the \a brush that is used for painting the background of the chart area.
173 Sets the \a brush that is used for painting the background of the chart area.
174 */
174 */
175 void QChart::setBackgroundBrush(const QBrush &brush)
175 void QChart::setBackgroundBrush(const QBrush &brush)
176 {
176 {
177 d_ptr->m_presenter->setBackgroundBrush(brush);
177 d_ptr->m_presenter->setBackgroundBrush(brush);
178 }
178 }
179
179
180 /*!
180 /*!
181 Gets the brush that is used for painting the background of the chart area.
181 Gets the brush that is used for painting the background of the chart area.
182 */
182 */
183 QBrush QChart::backgroundBrush() const
183 QBrush QChart::backgroundBrush() const
184 {
184 {
185 return d_ptr->m_presenter->backgroundBrush();
185 return d_ptr->m_presenter->backgroundBrush();
186 }
186 }
187
187
188 /*!
188 /*!
189 Sets the \a pen that is used for painting the background of the chart area.
189 Sets the \a pen that is used for painting the background of the chart area.
190 */
190 */
191 void QChart::setBackgroundPen(const QPen &pen)
191 void QChart::setBackgroundPen(const QPen &pen)
192 {
192 {
193 d_ptr->m_presenter->setBackgroundPen(pen);
193 d_ptr->m_presenter->setBackgroundPen(pen);
194 }
194 }
195
195
196 /*!
196 /*!
197 Gets the pen that is used for painting the background of the chart area.
197 Gets the pen that is used for painting the background of the chart area.
198 */
198 */
199 QPen QChart::backgroundPen() const
199 QPen QChart::backgroundPen() const
200 {
200 {
201 return d_ptr->m_presenter->backgroundPen();
201 return d_ptr->m_presenter->backgroundPen();
202 }
202 }
203
203
204 /*!
204 /*!
205 Sets the chart \a title. The description text that is drawn above the chart.
205 Sets the chart \a title. The description text that is drawn above the chart.
206 */
206 */
207 void QChart::setTitle(const QString &title)
207 void QChart::setTitle(const QString &title)
208 {
208 {
209 d_ptr->m_presenter->setTitle(title);
209 d_ptr->m_presenter->setTitle(title);
210 }
210 }
211
211
212 /*!
212 /*!
213 Returns the chart title. The description text that is drawn above the chart.
213 Returns the chart title. The description text that is drawn above the chart.
214 */
214 */
215 QString QChart::title() const
215 QString QChart::title() const
216 {
216 {
217 return d_ptr->m_presenter->title();
217 return d_ptr->m_presenter->title();
218 }
218 }
219
219
220 /*!
220 /*!
221 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
222 */
222 */
223 void QChart::setTitleFont(const QFont &font)
223 void QChart::setTitleFont(const QFont &font)
224 {
224 {
225 d_ptr->m_presenter->setTitleFont(font);
225 d_ptr->m_presenter->setTitleFont(font);
226 }
226 }
227
227
228 /*!
228 /*!
229 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 Gets the font that is used for drawing the chart description text that is rendered above the chart.
230 */
230 */
231 QFont QChart::titleFont() const
231 QFont QChart::titleFont() const
232 {
232 {
233 return d_ptr->m_presenter->titleFont();
233 return d_ptr->m_presenter->titleFont();
234 }
234 }
235
235
236 /*!
236 /*!
237 Sets the \a brush used for rendering the title text.
237 Sets the \a brush used for rendering the title text.
238 */
238 */
239 void QChart::setTitleBrush(const QBrush &brush)
239 void QChart::setTitleBrush(const QBrush &brush)
240 {
240 {
241 d_ptr->m_presenter->setTitleBrush(brush);
241 d_ptr->m_presenter->setTitleBrush(brush);
242 }
242 }
243
243
244 /*!
244 /*!
245 Returns the brush used for rendering the title text.
245 Returns the brush used for rendering the title text.
246 */
246 */
247 QBrush QChart::titleBrush() const
247 QBrush QChart::titleBrush() const
248 {
248 {
249 return d_ptr->m_presenter->titleBrush();
249 return d_ptr->m_presenter->titleBrush();
250 }
250 }
251
251
252 void QChart::setTheme(QChart::ChartTheme theme)
252 void QChart::setTheme(QChart::ChartTheme theme)
253 {
253 {
254 d_ptr->m_themeManager->setTheme(theme);
254 d_ptr->m_themeManager->setTheme(theme);
255 }
255 }
256
256
257 QChart::ChartTheme QChart::theme() const
257 QChart::ChartTheme QChart::theme() const
258 {
258 {
259 return d_ptr->m_themeManager->theme()->id();
259 return d_ptr->m_themeManager->theme()->id();
260 }
260 }
261
261
262 /*!
262 /*!
263 Zooms in the view by a factor of 2
263 Zooms in the view by a factor of 2
264 */
264 */
265 void QChart::zoomIn()
265 void QChart::zoomIn()
266 {
266 {
267 d_ptr->zoomIn(2.0);
267 d_ptr->zoomIn(2.0);
268 }
268 }
269
269
270 /*!
270 /*!
271 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 Zooms in the view to a maximum level at which \a rect is still fully visible.
272 */
272 */
273 void QChart::zoomIn(const QRectF &rect)
273 void QChart::zoomIn(const QRectF &rect)
274 {
274 {
275 d_ptr->zoomIn(rect);
275 d_ptr->zoomIn(rect);
276 }
276 }
277
277
278 /*!
278 /*!
279 Restores the view zoom level to the previous one.
279 Restores the view zoom level to the previous one.
280 */
280 */
281 void QChart::zoomOut()
281 void QChart::zoomOut()
282 {
282 {
283 d_ptr->zoomOut(2.0);
283 d_ptr->zoomOut(2.0);
284 }
284 }
285
285
286 /*!
286 /*!
287 Zooms in the view by a \a factor.
287 Zooms in the view by a \a factor.
288
288
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 */
290 */
291 void QChart::zoom(qreal factor)
291 void QChart::zoom(qreal factor)
292 {
292 {
293 if (qFuzzyCompare(factor, 0))
293 if (qFuzzyCompare(factor, 0))
294 return;
294 return;
295
295
296 if (qFuzzyCompare(factor, (qreal)1.0))
296 if (qFuzzyCompare(factor, (qreal)1.0))
297 return;
297 return;
298
298
299 if (factor < 0)
299 if (factor < 0)
300 return;
300 return;
301
301
302 if (factor > 1.0)
302 if (factor > 1.0)
303 d_ptr->zoomIn(factor);
303 d_ptr->zoomIn(factor);
304 else
304 else
305 d_ptr->zoomOut(1.0 / factor);
305 d_ptr->zoomOut(1.0 / factor);
306 }
306 }
307
307
308 /*!
308 /*!
309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
309 Returns the pointer to the x axis object of the chart asociated with the specified \a series
310 If no series is provided then pointer to currently visible axis is provided
310 If no series is provided then pointer to currently visible axis is provided
311 */
311 */
312 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
312 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
313 {
313 {
314 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
314 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
315 if (axisList.count())
315 if (axisList.count())
316 return axisList[0];
316 return axisList[0];
317 return 0;
317 return 0;
318 }
318 }
319
319
320 /*!
320 /*!
321 Returns the pointer to the y axis object of the chart asociated with the specified \a series
321 Returns the pointer to the y axis object of the chart asociated with the specified \a series
322 If no series is provided then pointer to currently visible axis is provided
322 If no series is provided then pointer to currently visible axis is provided
323 */
323 */
324 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
324 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
325 {
325 {
326 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
326 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
327 if (axisList.count())
327 if (axisList.count())
328 return axisList[0];
328 return axisList[0];
329 return 0;
329 return 0;
330 }
330 }
331
331
332 /*!
332 /*!
333 Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the
333 Returns the axes added for the \a series with \a orientation. If no series is provided, then all axes with the
334 specified orientation are returned.
334 specified orientation are returned.
335 \sa addAxis(), createDefaultAxes()
335 \sa addAxis(), createDefaultAxes()
336 */
336 */
337 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
337 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
338 {
338 {
339 QList<QAbstractAxis *> result ;
339 QList<QAbstractAxis *> result ;
340
340
341 if (series) {
341 if (series) {
342 foreach (QAbstractAxis *axis, series->attachedAxes()){
342 foreach (QAbstractAxis *axis, series->attachedAxes()){
343 if (orientation.testFlag(axis->orientation()))
343 if (orientation.testFlag(axis->orientation()))
344 result << axis;
344 result << axis;
345 }
345 }
346 } else {
346 } else {
347 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
347 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
348 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
348 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
349 result << axis;
349 result << axis;
350 }
350 }
351 }
351 }
352
352
353 return result;
353 return result;
354 }
354 }
355
355
356 /*!
356 /*!
357 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
357 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
358
358
359 Creates the axes for the chart based on the series that has already been added to the chart.
359 Creates the axes for the chart based on the series that has already been added to the chart.
360
360
361 \table
361 \table
362 \header
362 \header
363 \o Series type
363 \o Series type
364 \o X-axis
364 \o X-axis
365 \o Y-axis
365 \o Y-axis
366 \row
366 \row
367 \o QXYSeries
367 \o QXYSeries
368 \o QValueAxis
368 \o QValueAxis
369 \o QValueAxis
369 \o QValueAxis
370 \row
370 \row
371 \o QBarSeries
371 \o QBarSeries
372 \o QBarCategoryAxis
372 \o QBarCategoryAxis
373 \o QValueAxis
373 \o QValueAxis
374 \row
374 \row
375 \o QPieSeries
375 \o QPieSeries
376 \o None
376 \o None
377 \o None
377 \o None
378 \endtable
378 \endtable
379
379
380 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
380 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
381 If there are sevaral series added of different types then each series gets its own axes pair.
381 If there are sevaral series added of different types then each series gets its own axes pair.
382
382
383 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
383 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
384
384
385 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
385 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
386 QPieSeries does not create any axes.
386 QPieSeries does not create any axes.
387
387
388 \sa axisX(), axisY(), setAxisX(), setAxisY()
388 \sa axisX(), axisY(), setAxisX(), setAxisY()
389 */
389 */
390 void QChart::createDefaultAxes()
390 void QChart::createDefaultAxes()
391 {
391 {
392 d_ptr->m_dataset->createDefaultAxes();
392 d_ptr->m_dataset->createDefaultAxes();
393 }
393 }
394
394
395 /*!
395 /*!
396 Returns the legend object of the chart. Ownership stays in chart.
396 Returns the legend object of the chart. Ownership stays in chart.
397 */
397 */
398 QLegend *QChart::legend() const
398 QLegend *QChart::legend() const
399 {
399 {
400 return d_ptr->m_legend;
400 return d_ptr->m_legend;
401 }
401 }
402
402
403 /*!
403 /*!
404 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
404 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
405 Deprecated. Use setMargins().
405 Deprecated. Use setMargins().
406 */
406 */
407 void QChart::setMinimumMargins(const QMargins &margins)
407 void QChart::setMinimumMargins(const QMargins &margins)
408 {
408 {
409 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
409 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
410 d_ptr->m_presenter->layout()->setMargins(margins);
410 d_ptr->m_presenter->layout()->setMargins(margins);
411 }
411 }
412
412
413 /*!
413 /*!
414 Returns the rect that contains information about margins (distance between chart widget edge and axes).
414 Returns the rect that contains information about margins (distance between chart widget edge and axes).
415 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
415 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
416 Deprecated. Use margins().
416 Deprecated. Use margins().
417 */
417 */
418 QMargins QChart::minimumMargins() const
418 QMargins QChart::minimumMargins() const
419 {
419 {
420 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
420 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
421 return d_ptr->m_presenter->layout()->margins();
421 return d_ptr->m_presenter->layout()->margins();
422 }
422 }
423
423
424 /*!
424 /*!
425 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
425 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
426 */
426 */
427 void QChart::setMargins(const QMargins &margins)
427 void QChart::setMargins(const QMargins &margins)
428 {
428 {
429 d_ptr->m_presenter->layout()->setMargins(margins);
429 d_ptr->m_presenter->layout()->setMargins(margins);
430 }
430 }
431
431
432 /*!
432 /*!
433 Returns the rect that contains information about margins (distance between chart widget edge and axes).
433 Returns the rect that contains information about margins (distance between chart widget edge and axes).
434 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
434 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
435 */
435 */
436 QMargins QChart::margins() const
436 QMargins QChart::margins() const
437 {
437 {
438 return d_ptr->m_presenter->layout()->margins();
438 return d_ptr->m_presenter->layout()->margins();
439 }
439 }
440
440
441 /*!
441 /*!
442 Returns the the rect within which the drawing of the chart is done.
442 Returns the the rect within which the drawing of the chart is done.
443 It does not include the area defines by margins.
443 It does not include the area defines by margins.
444 */
444 */
445 QRectF QChart::plotArea() const
445 QRectF QChart::plotArea() const
446 {
446 {
447 return d_ptr->m_presenter->geometry();
447 return d_ptr->m_presenter->geometry();
448 }
448 }
449
449
450 /*!
450 /*!
451 Sets animation \a options for the chart
451 Sets animation \a options for the chart
452 */
452 */
453 void QChart::setAnimationOptions(AnimationOptions options)
453 void QChart::setAnimationOptions(AnimationOptions options)
454 {
454 {
455 d_ptr->m_presenter->setAnimationOptions(options);
455 d_ptr->m_presenter->setAnimationOptions(options);
456 }
456 }
457
457
458 QChart::AnimationOptions QChart::animationOptions() const
458 QChart::AnimationOptions QChart::animationOptions() const
459 {
459 {
460 return d_ptr->m_presenter->animationOptions();
460 return d_ptr->m_presenter->animationOptions();
461 }
461 }
462
462
463 /*!
463 /*!
464 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
464 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
465 */
465 */
466 void QChart::scroll(qreal dx, qreal dy)
466 void QChart::scroll(qreal dx, qreal dy)
467 {
467 {
468 d_ptr->scroll(dx,dy);
468 d_ptr->scroll(dx,dy);
469 }
469 }
470
470
471 void QChart::setBackgroundVisible(bool visible)
471 void QChart::setBackgroundVisible(bool visible)
472 {
472 {
473 d_ptr->m_presenter->setBackgroundVisible(visible);
473 d_ptr->m_presenter->setBackgroundVisible(visible);
474 }
474 }
475
475
476 bool QChart::isBackgroundVisible() const
476 bool QChart::isBackgroundVisible() const
477 {
477 {
478 return d_ptr->m_presenter->isBackgroundVisible();
478 return d_ptr->m_presenter->isBackgroundVisible();
479 }
479 }
480
480
481 void QChart::setDropShadowEnabled(bool enabled)
481 void QChart::setDropShadowEnabled(bool enabled)
482 {
482 {
483 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
483 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
484 }
484 }
485
485
486 bool QChart::isDropShadowEnabled() const
486 bool QChart::isDropShadowEnabled() const
487 {
487 {
488 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
488 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
489 }
489 }
490
490
491 /*!
491 /*!
492 Returns all the series that are added to the chart.
492 Returns all the series that are added to the chart.
493
493
494 \sa addSeries(), removeSeries(), removeAllSeries()
494 \sa addSeries(), removeSeries(), removeAllSeries()
495 */
495 */
496 QList<QAbstractSeries *> QChart::series() const
496 QList<QAbstractSeries *> QChart::series() const
497 {
497 {
498 return d_ptr->m_dataset->series();
498 return d_ptr->m_dataset->series();
499 }
499 }
500
500
501 /*!
501 /*!
502 Sets \a axis to the chart, which will control the presentation of the \a series
502 Sets \a axis to the chart, which will control the presentation of the \a series
503
503
504 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
504 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
505 */
505 */
506 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
506 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
507 {
507 {
508 QList<QAbstractAxis*> list = axes(Qt::Horizontal,series);
508 QList<QAbstractAxis*> list = axes(Qt::Horizontal,series);
509
509
510 foreach(QAbstractAxis* a, list){
510 foreach(QAbstractAxis* a, list){
511 d_ptr->m_dataset->removeAxis(a);
511 d_ptr->m_dataset->removeAxis(a);
512 delete a;
512 delete a;
513 }
513 }
514
514
515 if(!d_ptr->m_dataset->axes().contains(axis))
515 if(!d_ptr->m_dataset->axes().contains(axis))
516 d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom);
516 d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom);
517 d_ptr->m_dataset->attachAxis(series,axis);
517 d_ptr->m_dataset->attachAxis(series,axis);
518 }
518 }
519
519
520 /*!
520 /*!
521 Sets \a axis to the chart, which will control the presentation of the \a series
521 Sets \a axis to the chart, which will control the presentation of the \a series
522
522
523 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
523 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
524 */
524 */
525 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
525 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
526 {
526 {
527 QList<QAbstractAxis*> list = axes(Qt::Vertical,series);
527 QList<QAbstractAxis*> list = axes(Qt::Vertical,series);
528
528
529 foreach(QAbstractAxis* a, list) {
529 foreach(QAbstractAxis* a, list) {
530 d_ptr->m_dataset->removeAxis(a);
530 d_ptr->m_dataset->removeAxis(a);
531 delete a;
531 delete a;
532 }
532 }
533
533
534 if(!d_ptr->m_dataset->axes().contains(axis))
534 if(!d_ptr->m_dataset->axes().contains(axis))
535 d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft);
535 d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft);
536 d_ptr->m_dataset->attachAxis(series,axis);
536 d_ptr->m_dataset->attachAxis(series,axis);
537 }
537 }
538
538
539 /*!
539 /*!
540 Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
540 Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
541 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
541 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
542 */
542 */
543 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
543 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
544 {
544 {
545 d_ptr->m_dataset->addAxis(axis, alignment);
545 d_ptr->m_dataset->addAxis(axis, alignment);
546 }
546 }
547
547
548 /*!
548 /*!
549 Removes \a axis from the chart. The ownership is returned to the caller.
549 Removes \a axis from the chart. The ownership is returned to the caller.
550 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
550 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
551 */
551 */
552 void QChart::removeAxis(QAbstractAxis *axis)
552 void QChart::removeAxis(QAbstractAxis *axis)
553 {
553 {
554 d_ptr->m_dataset->removeAxis(axis);
554 d_ptr->m_dataset->removeAxis(axis);
555 }
555 }
556
556
557 /*!
557 /*!
558 Returns the value in the \a series domain that coresponds to the charts widget point defines by \a position.
558 Returns the value in the \a series domain that corresponds to the charts widget point defines by \a position.
559 */
559 */
560 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
560 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
561 {
561 {
562 return d_ptr->m_dataset->mapToValue(position, series);
562 return d_ptr->m_dataset->mapToValue(position, series);
563 }
563 }
564
564
565 /*!
565 /*!
566 Returns the position on the charts widget that coresponds to the \a value in the \a series domain.
566 Returns the position on the charts widget that corresponds to the \a value in the \a series domain.
567 */
567 */
568 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
568 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
569 {
569 {
570 return d_ptr->m_dataset->mapToPosition(value, series);
570 return d_ptr->m_dataset->mapToPosition(value, series);
571 }
571 }
572
572
573 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
573 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
574
574
575 QChartPrivate::QChartPrivate(QChart *q):
575 QChartPrivate::QChartPrivate(QChart *q):
576 q_ptr(q),
576 q_ptr(q),
577 m_legend(0),
577 m_legend(0),
578 m_dataset(new ChartDataSet(q)),
578 m_dataset(new ChartDataSet(q)),
579 m_presenter(new ChartPresenter(q)),
579 m_presenter(new ChartPresenter(q)),
580 m_themeManager(new ChartThemeManager(q))
580 m_themeManager(new ChartThemeManager(q))
581 {
581 {
582 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
582 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
583 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
583 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
584 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
584 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
585 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
585 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
586 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
586 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
587 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
587 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
588 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
588 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
589 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
589 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
590 }
590 }
591
591
592 QChartPrivate::~QChartPrivate()
592 QChartPrivate::~QChartPrivate()
593 {
593 {
594
594
595 }
595 }
596
596
597 void QChartPrivate::zoomIn(qreal factor)
597 void QChartPrivate::zoomIn(qreal factor)
598 {
598 {
599 QRectF rect = m_presenter->geometry();
599 QRectF rect = m_presenter->geometry();
600 rect.setWidth(rect.width() / factor);
600 rect.setWidth(rect.width() / factor);
601 rect.setHeight(rect.height() / factor);
601 rect.setHeight(rect.height() / factor);
602 rect.moveCenter(m_presenter->geometry().center());
602 rect.moveCenter(m_presenter->geometry().center());
603 zoomIn(rect);
603 zoomIn(rect);
604 }
604 }
605
605
606 void QChartPrivate::zoomIn(const QRectF &rect)
606 void QChartPrivate::zoomIn(const QRectF &rect)
607 {
607 {
608 if (!rect.isValid())
608 if (!rect.isValid())
609 return;
609 return;
610
610
611 QRectF r = rect.normalized();
611 QRectF r = rect.normalized();
612 const QRectF geometry = m_presenter->geometry();
612 const QRectF geometry = m_presenter->geometry();
613 r.translate(-geometry.topLeft());
613 r.translate(-geometry.topLeft());
614
614
615 if (!r.isValid())
615 if (!r.isValid())
616 return;
616 return;
617
617
618 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
618 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
619 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
619 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
620 m_dataset->zoomInDomain(r);
620 m_dataset->zoomInDomain(r);
621 m_presenter->setState(ChartPresenter::ShowState,QPointF());
621 m_presenter->setState(ChartPresenter::ShowState,QPointF());
622
622
623 }
623 }
624
624
625 void QChartPrivate::zoomOut(qreal factor)
625 void QChartPrivate::zoomOut(qreal factor)
626 {
626 {
627 const QRectF geometry = m_presenter->geometry();
627 const QRectF geometry = m_presenter->geometry();
628
628
629 QRectF r;
629 QRectF r;
630 r.setSize(geometry.size() / factor);
630 r.setSize(geometry.size() / factor);
631 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
631 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
632 if (!r.isValid())
632 if (!r.isValid())
633 return;
633 return;
634
634
635 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
635 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
636 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
636 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
637 m_dataset->zoomOutDomain(r);
637 m_dataset->zoomOutDomain(r);
638 m_presenter->setState(ChartPresenter::ShowState,QPointF());
638 m_presenter->setState(ChartPresenter::ShowState,QPointF());
639 }
639 }
640
640
641 void QChartPrivate::scroll(qreal dx, qreal dy)
641 void QChartPrivate::scroll(qreal dx, qreal dy)
642 {
642 {
643 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
643 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
644 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
644 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
645 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
645 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
646 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
646 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
647
647
648 m_dataset->scrollDomain(dx, dy);
648 m_dataset->scrollDomain(dx, dy);
649 m_presenter->setState(ChartPresenter::ShowState,QPointF());
649 m_presenter->setState(ChartPresenter::ShowState,QPointF());
650 }
650 }
651
651
652 #include "moc_qchart.cpp"
652 #include "moc_qchart.cpp"
653
653
654 QTCOMMERCIALCHART_END_NAMESPACE
654 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now