##// END OF EJS Templates
Example finalization and documentation...
Mika Salmela -
r2556:89b8a97da4fc
parent child
Show More
@@ -0,0 +1,13
1 # BoxWhisk Inc share deviation in 2012
2 Jan 25.74 25.28 25.86 26.05 26.64 28.47 28.30 29.22 29.72 27.50 25.62 25.50 25.15 26.47 27.41 25.78 24.82 24.89 24.88 24.60 23.85
3 Feb 30.79 29.62 29.67 30.37 30.16 30.22 31.02 33.70 32.60 32.24 31.98 31.79 31.10 30.79 31.53 30.92 29.00 29.58 30.37 29.40 28.60
4 Mar 29.64 29.34 30.13 30.43 31.75 30.77 30.72 31.52 32.12 33.75 33.51 33.69 32.83 32.47 32.41 32.39 32.78 31.08 29.46 31.58 31.39 31.41
5 Apr 24.96 25.62 25.19 28.37 28.78 26.50 25.90 26.40 26.86 26.90 27.91 27.32 27.99 26.86 26.68 27.57 27.50 26.96 26.50
6 May 21.85 21.08 22.98 22.61 22.45 21.73 21.71 23.27 22.14 19.65 22.95 21.23 23.17 24.26 24.17 21.97 22.53 25.49 25.51 26.46 26.65
7 Jun 15.08 15.19 15.36 15.21 15.31 18.19 18.30 15.53 15.35 15.80 15.17 16.95 18.25 20.52 20.61 20.40 20.45 19.43 19.11 19.74
8 Jul 17.75 18.24 17.57 16.53 15.98 16.06 16.64 17.69 17.91 19.00 19.03 19.14 19.10 17.86 19.12 19.53 19.43 19.30 19.03 19.76 18.79 18.33
9 Aug 19.69 19.54 19.39 19.49 19.96 19.72 20.25 20.70 21.13 20.74 20.27 19.25 18.72 19.02 19.20 19.24 19.60 19.22 19.60 18.98 18.27 17.70 18.19
10 Sep 19.35 19.82 19.96 20.96 20.75 21.55 21.68 22.19 22.14 22.48 22.45 21.74 21.97 21.18 20.66 20.54 19.89 19.39 19.26 19.86
11 Oct 17.95 17.80 17.45 17.89 18.38 18.12 17.85 18.59 18.65 18.46 18.43 18.30 18.87 19.61 19.55 19.59 20.27 20.54 21.02 20.23 19.05 19.52 19.71
12 Now 20.36 20.29 19.22 19.74 20.05 20.13 19.67 19.19 18.94 19.04 18.49 18.53 18.64 19.00 19.21 19.19 19.30 19.11 19.17 18.76 18.80 18.52
13 Dec 22.95 22.19 22.15 21.42 21.39 21.65 22.39 20.86 20.48 20.70 20.94 20.82 19.25 21.21 19.63 20.55
1 NO CONTENT: modified file, binary diff hidden
@@ -3,36 +3,74
3 3 \title Box and Whiskers Example
4 4 \subtitle
5 5
6 The example shows how to create a box-and-whiskers chart.
6 The example shows how to create a box-and-whiskers chart. It also shows how to read the non-continuous data from the file,
7 arrange it and find medians needed for box-and-whiskers plotting.
7 8
8 \image examples_barchart.png
9 \image examples_boxplotchart.png
9 10
10 Introduction here
11 To show the share deviation of two companies we start by creating two QBoxPlotSeries to handle monthly data.
11 12
12 \snippet ../examples/barchart/main.cpp 1
13 \snippet ../examples/boxplotchart/main.cpp 1
13 14
14 Ykk�skohta
15 QFile class is used to open a text file where the non-continuous data is kept. The BoxDataReader is an auxiliary class for
16 reading the text file and finding the extreme and median values from the data. The BoxDataReader is explained in more detail later.
17 The method readBox reads the values and sets them to the QBoxSet item which the method returns for the caller. The returned QBoxSet
18 item is added to the series.
15 19
16 \snippet ../examples/barchart/main.cpp 2
20 \snippet ../examples/boxplotchart/main.cpp 2
17 21
18 Kakkoskohta
22 In this section a second file is opened for reading the data for the second company.
19 23
20 \snippet ../examples/barchart/main.cpp 3
24 \snippet ../examples/boxplotchart/main.cpp 3
21 25
22 Kolmoskohta
26 In this code snippet a new QChart instance is created and previously created series are added to it. Also title is defined and
27 animation is set to be SeriesAnimation.
23 28
24 \snippet ../examples/barchart/main.cpp 4
29 \snippet ../examples/boxplotchart/main.cpp 4
25 30
26 Neloskohta
31 Here we ask chart to create default axes for our presentation. We also set range for vertical axis by querying the pointer
32 for the axis from the chart and then setting the min and max for that axis.
27 33
28 \snippet ../examples/barchart/main.cpp 5
34 \snippet ../examples/boxplotchart/main.cpp 5
29 35
30 Tarkista numerointi. Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
36 In this section we set legends visible and place them at the bottom of the chart.
31 37
32 \snippet ../examples/barchart/main.cpp 6
38 \snippet ../examples/boxplotchart/main.cpp 6
33 39
34 Tarkista numerointi. Chart is ready to be shown. We set the chart to be central widget of the window.
40 Finally we add the chart onto a view. We also turn on the antialiasing for the chartView.
41
42 \snippet ../examples/boxplotchart/main.cpp 7
43
44 The chart is ready to be shown. We set the chart to be central widget of the window.
35 45 We also set the size for the chart window and show it.
36 46
37 \snippet ../examples/barchart/main.cpp 7
47 \snippet ../examples/boxplotchart/main.cpp 8
48
49 Here the method readBox is explained in detail. Firstly a line is read from the file and lines starting with # are rejected
50 since they are considered as comment lines.
51
52 \snippet ../examples/boxplotchart/boxdatareader.cpp 1
53
54 On the file the data is arranged as number, space, number, space and so on. On this snippet the line is split into single number strings which
55 are stored on QStringList.
56
57 \snippet ../examples/boxplotchart/boxdatareader.cpp 2
58
59 The sortedList will hold the numbers in continuous order and in this code segment we show how to do it. First the sortedList is cleared and numbers
60 are read from the strList and stored into sortedList in double format. The qSort method arranges the sortedList into continuous order
61 starting from the smallest.
62
63 \snippet ../examples/boxplotchart/boxdatareader.cpp 3
64
65 Here is a code sample how to select extremes and medians from the continuous data. Firstly a new QBoxSet is created.
66 Lower and upper extremes are simple to select; they are just first and last items on the sortedList. For medians we use a helper
67 method findMedian which is explained later. For the median from the upper half we need to adjust the begin number if
68 amount of the numbers is even or uneven. The end number for lower half comes naturally from int rounding.
69
70 \snippet ../examples/boxplotchart/boxdatareader.cpp 4
71
72 Here's the code sample for the method findMedian. If the amount of numbers is uneven we select the number from
73 the middle. For even amount numbers we take two numbers from the middle and calculate the mean value.
74
75 \snippet ../examples/boxplotchart/boxdatareader.cpp 5
38 76 */
@@ -18,118 +18,125
18 18
19 19 <tr>
20 20 <td><a href="examples-barmodelmapper.html">Bar Chart from Model</a></td>
21 <td><a href="examples-customchart.html">Custom Chart</a></td>
21 <td><a href="examples-boxplotchart.html">Box-and-whiskers Chart</a></td>
22 22 </tr>
23 23 <tr>
24 24 <td><a href="examples-barmodelmapper.html"><img src="images/examples_barmodelmapper.png" width="300" alt="Bar Chart from Model" /></a></td>
25 <td><a href="examples-customchart.html"><img src="images/examples_customchart.png" width="300" alt="Custom Chart" /></a></td>
25 <td><a href="examples-boxplotchart.html"><img src="images/examples_boxplotchart.png" width="300" alt="Bar Chart from Model" /></a></td>
26 26 </tr>
27 27
28 28 <tr>
29 <td><a href="examples-customchart.html">Custom Chart</a></td>
29 30 <td><a href="examples-datetimeaxis.html">DateTimeAxis Example</a></td>
30 <td><a href="examples-donutbreakdown.html">Donut Breakdown Chart</a></td>
31 31 </tr>
32 32 <tr>
33 <td><a href="examples-customchart.html"><img src="images/examples_customchart.png" width="300" alt="Custom Chart" /></a></td>
33 34 <td><a href="examples-datetimeaxis.html"><img src="images/examples_datetimeaxis.png" width="300" alt="DateTimeAxis Example" /></a></td>
34 <td><a href="examples-donutbreakdown.html"><img src="images/examples_donutbreakdown.png" width="300" alt="Donut Breakdown Chart" /></a></td>
35 35 </tr>
36 36
37 37 <tr>
38 <td><a href="examples-donutbreakdown.html">Donut Breakdown Chart</a></td>
38 39 <td><a href="examples-donutchart.html">Donut Chart</a></td>
39 <td><a href="examples-horizontalbarchart.html">Horizontal Bar Chart</a></td>
40 40 </tr>
41 41 <tr>
42 <td><a href="examples-donutbreakdown.html"><img src="images/examples_donutbreakdown.png" width="300" alt="Donut Breakdown Chart" /></a></td>
42 43 <td><a href="examples-donutchart.html"><img src="images/examples_donutchart.png" width="300" alt="Donut Chart" /></a></td>
43 <td><a href="examples-horizontalbarchart.html"><img src="images/examples_horizontalbarchart.png" width="300" alt="Horizontal Bar Chart" /></a></td>
44 44 </tr>
45 45
46 46 <tr>
47 <td><a href="examples-horizontalbarchart.html">Horizontal Bar Chart</a></td>
47 48 <td><a href="examples-horizontalpercentbarchart.html">Horizontal Percent Bar Chart</a></td>
48 <td><a href="examples-horizontalstackedbarchart.html">Horizontal Stacked Bar Chart</a></td>
49 49 </tr>
50 50 <tr>
51 <td><a href="examples-horizontalbarchart.html"><img src="images/examples_horizontalbarchart.png" width="300" alt="Horizontal Bar Chart" /></a></td>
51 52 <td><a href="examples-horizontalpercentbarchart.html"><img src="images/examples_horizontalpercentbarchart.png" width="300" alt="Horizontal Percent Bar Chart" /></a></td>
52 <td><a href="examples-horizontalstackedbarchart.html"><img src="images/examples_horizontalstackedbarchart.png" width="300" alt="Horizontal Stacked Bar Chart" /></a></td>
53 53 </tr>
54 54
55 55 <tr>
56 <td><a href="examples-horizontalstackedbarchart.html">Horizontal Stacked Bar Chart</a></td>
56 57 <td><a href="examples-legend.html">Legend</a></td>
57 <td><a href="examples-legendmarkers.html">Legend Markers</a></td>
58 58 </tr>
59 59 <tr>
60 <td><a href="examples-horizontalstackedbarchart.html"><img src="images/examples_horizontalstackedbarchart.png" width="300" alt="Horizontal Stacked Bar Chart" /></a></td>
60 61 <td><a href="examples-legend.html"><img src="images/examples_legend_detach.png" width="300" alt="Legend" /></a></td>
61 <td><a href="examples-legendmarkers.html"><img src="images/examples_legendmarkers.png" width="300" alt="Legend Markers" /></a></td>
62 62 </tr>
63 63
64 64 <tr>
65 <td><a href="examples-legendmarkers.html">Legend Markers</a></td>
65 66 <td><a href="examples-lineandbar.html">Line and Barchart</a></td>
66 <td><a href="examples-linechart.html">Line Chart</a></td>
67 67 </tr>
68 68 <tr>
69 <td><a href="examples-legendmarkers.html"><img src="images/examples_legendmarkers.png" width="300" alt="Legend Markers" /></a></td>
69 70 <td><a href="examples-lineandbar.html"><img src="images/examples_lineandbar.png" width="300" alt="Line and Barchart" /></a></td>
70 <td><a href="examples-linechart.html"><img src="images/examples_linechart.png" width="300" alt="Line Chart" /></a></td>
71 71 </tr>
72 72
73 73 <tr>
74 <td><a href="examples-linechart.html">Line Chart</a></td>
74 75 <td><a href="examples-logvalueaxis.html">Logarithmic axis</a></td>
75 <td><a href="examples-modeldata.html">Model Data</a></td>
76 76 </tr>
77 77 <tr>
78 <td><a href="examples-linechart.html"><img src="images/examples_linechart.png" width="300" alt="Line Chart" /></a></td>
78 79 <td><a href="examples-logvalueaxis.html"><img src="images/examples_logvalueaxis.png" width="300" alt="Logarythmix axis" /></a></td>
79 <td><a href="examples-modeldata.html"><img src="images/examples_modeldata.png" width="300" alt="Model Data" /></a></td>
80 80 </tr>
81 81
82 82 <tr>
83 <td><a href="examples-modeldata.html">Model Data</a></td>
83 84 <td><a href="examples-multiaxis.html">Multiple axes</a></td>
84 <td><a href="examples-percentbarchart.html">Percent Bar Chart</a></td>
85 85 </tr>
86 86 <tr>
87 <td><a href="examples-modeldata.html"><img src="images/examples_modeldata.png" width="300" alt="Model Data" /></a></td>
87 88 <td><a href="examples-multiaxis.html"><img src="images/examples_multiaxis.png" width="300" alt="Multiple axes" /></a></td>
88 <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="300" alt="Percent Bar Chart" /></a></td>
89 89 </tr>
90 90
91 91 <tr>
92 <td><a href="examples-percentbarchart.html">Percent Bar Chart</a></td>
92 93 <td><a href="examples-piechart.html">Pie Chart</a></td>
93 <td><a href="examples-piechartdrilldown.html">Pie Chart Drilldown</a></td>
94 94 </tr>
95 95 <tr>
96 <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="300" alt="Percent Bar Chart" /></a></td>
96 97 <td><a href="examples-piechart.html"><img src="images/examples_piechart.png" width="300" alt="Pie Chart" /></a></td>
97 <td><a href="examples-piechartdrilldown.html"><img src="images/examples_piechartdrill2.png" width="300" alt="Pie Chart Drilldown" /></a></td>
98 98 </tr>
99 99
100 100 <tr>
101 <td><a href="examples-piechartdrilldown.html">Pie Chart Drilldown</a></td>
101 102 <td><a href="examples-polarchart.html">Polar chart</a></td>
102 <td><a href="examples-scatterchart.html">Scatter chart</a></td>
103 103 </tr>
104 104 <tr>
105 <td><a href="examples-piechartdrilldown.html"><img src="images/examples_piechartdrill2.png" width="300" alt="Pie Chart Drilldown" /></a></td>
105 106 <td><a href="examples-polarchart.html"><img src="images/examples_polarchart.png" width="300" alt="Polar chart" /></a></td>
106 <td><a href="examples-scatterchart.html"><img src="images/examples_scatterchart.png" width="300" alt="Scatter chart" /></a></td>
107 107 </tr>
108 108
109 109 <tr>
110 <td><a href="examples-scatterchart.html">Scatter chart</a></td>
110 111 <td><a href="examples-scatterinteractions.html">Scatter Interactions</a></td>
111 <td><a href="examples-splinechart.html">Spline Chart</a></td>
112 112 </tr>
113 113 <tr>
114 <td><a href="examples-scatterchart.html"><img src="images/examples_scatterchart.png" width="300" alt="Scatter chart" /></a></td>
114 115 <td><a href="examples-scatterinteractions.html"><img src="images/examples_scatterinteractions.png" width="300" alt="Scatter Interactions" /></a></td>
115 <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="300" alt="Spline Chart" /></a></td>
116 116 </tr>
117 117
118 118 <tr>
119 <td><a href="examples-splinechart.html">Spline Chart</a></td>
119 120 <td><a href="examples-stackedbarchart.html">Stacked Bar Chart</a></td>
120 <td><a href="examples-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown</a></td>
121 121 </tr>
122 122 <tr>
123 <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="300" alt="Spline Chart" /></a></td>
123 124 <td><a href="examples-stackedbarchart.html"><img src="images/examples_stackedbarchart.png" width="300" alt="Stacked Bar Chart" /></a></td>
124 <td><a href="examples-stackedbarchartdrilldown.html"><img src="images/examples_stackedbarchartdrilldown1.png" width="300" alt="Stacked Bar Chart Drilldown" /></a></td>
125 125 </tr>
126 126
127 127 <tr>
128 <td><a href="examples-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown</a></td>
128 129 <td><a href="examples-temperaturerecords.html">Temperature Records</a></td>
129 <td><a href="examples-zoomlinechart.html">Zoom Line</a></td>
130 130 </tr>
131 131 <tr>
132 <td><a href="examples-stackedbarchartdrilldown.html"><img src="images/examples_stackedbarchartdrilldown1.png" width="300" alt="Stacked Bar Chart Drilldown" /></a></td>
132 133 <td><a href="examples-temperaturerecords.html"><img src="images/examples_temperaturerecords.png" width="300" alt="Temperature Records" /></a></td>
134 </tr>
135
136 <tr>
137 <td><a href="examples-zoomlinechart.html">Zoom Line</a></td>
138 </tr>
139 <tr>
133 140 <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart1.png" width="300" alt="Zoom Line" /></a></td>
134 141 </tr>
135 142
1 NO CONTENT: file renamed from examples/boxplotchart/stock_data.txt to examples/boxplotchart/acme_data.txt
@@ -25,43 +25,55 BoxDataReader::BoxDataReader(QIODevice *device) :
25 25 {
26 26 }
27 27
28 void BoxDataReader::readFile(QIODevice *device)
29 {
30 QTextStream::setDevice(device);
31 }
32
28 33 QBoxSet* BoxDataReader::readBox()
29 34 {
35 //! [1]
30 36 QString line = readLine();
31 37 if (line.startsWith("#"))
32 38 return 0;
39 //! [1]
33 40
41 //! [2]
34 42 QStringList strList = line.split(" ", QString::SkipEmptyParts);
35 sortedList.clear();
43 //! [2]
36 44
45 //! [3]
46 sortedList.clear();
37 47 for (int i = 1; i < strList.count(); i++)
38 48 sortedList.append(strList.at(i).toDouble());
39 49
40 50 qSort(sortedList.begin(), sortedList.end());
51 //! [3]
41 52
42 53 int count = sortedList.count();
43 54
55 //! [4]
44 56 QBoxSet *box = new QBoxSet(strList.first());
45 57 box->setValue(QBoxSet::LowerExtreme, sortedList.first());
46 58 box->setValue(QBoxSet::UpperExtreme, sortedList.last());
47 59 box->setValue(QBoxSet::Median, findMedian(0, count));
48 60 box->setValue(QBoxSet::LowerQuartile, findMedian(0, count / 2));
49 if (count % 2)
50 box->setValue(QBoxSet::UpperQuartile, findMedian(count / 2 + 1, count));
51 else // even amount of numbers
52 box->setValue(QBoxSet::UpperQuartile, findMedian(count / 2, count));
61 box->setValue(QBoxSet::UpperQuartile, findMedian(count / 2 + (count % 2), count));
62 //! [4]
53 63
54 64 return box;
55 65 }
56 66
57 67 qreal BoxDataReader::findMedian(int begin, int end)
58 68 {
69 //! [5]
59 70 int count = end - begin;
60 71 if (count % 2 ) {
61 return sortedList.at(int(count/2) + begin);
72 return sortedList.at(count / 2 + begin);
62 73 } else {
63 74 qreal right = sortedList.at(count / 2 + begin);
64 75 qreal left = sortedList.at(count / 2 - 1 + begin);
65 76 return (right + left) / 2.0;
66 77 }
78 //! [5]
67 79 }
@@ -31,6 +31,7 class BoxDataReader : public QTextStream
31 31 public:
32 32 explicit BoxDataReader(QIODevice *device);
33 33 QBoxSet* readBox();
34 void readFile(QIODevice *device);
34 35
35 36 protected:
36 37 qreal findMedian(int begin, int end);
@@ -1,5 +1,6
1 1 <RCC>
2 2 <qresource prefix="/">
3 <file alias="stock">stock_data.txt</file>
3 <file alias="acme">acme_data.txt</file>
4 <file alias="boxwhisk">boxwhisk_data.txt</file>
4 5 </qresource>
5 6 </RCC>
@@ -33,52 +33,71 QTCOMMERCIALCHART_USE_NAMESPACE
33 33 int main(int argc, char *argv[])
34 34 {
35 35 QApplication a(argc, argv);
36
37 //! [1]
38 QBoxPlotSeries *acmeSeries = new QBoxPlotSeries();
39 acmeSeries->setName("Acme Ltd");
40
41 QBoxPlotSeries *boxWhiskSeries = new QBoxPlotSeries();
42 boxWhiskSeries->setName("BoxWhisk Inc");
36 43 //![1]
37 44
38 45 //![2]
39 QBoxPlotSeries *series = new QBoxPlotSeries();
40 series->setName("Acme Ltd");
46 QFile acmeData(":acme");
47 if (!acmeData.open(QIODevice::ReadOnly | QIODevice::Text))
48 return 1;
49
50 BoxDataReader dataReader(&acmeData);
51 while (!dataReader.atEnd()) {
52 QBoxSet *set = dataReader.readBox();
53 if (set)
54 acmeSeries->append(set);
55 }
41 56 //![2]
42 57
43 QFile stockData(":stock");
44 if (!stockData.open(QIODevice::ReadOnly | QIODevice::Text))
58 //! [3]
59 QFile boxwhiskData(":boxwhisk");
60 if (!boxwhiskData.open(QIODevice::ReadOnly | QIODevice::Text))
45 61 return 1;
46 62
47 BoxDataReader dataReader(&stockData);
63 dataReader.readFile(&boxwhiskData);
48 64 while (!dataReader.atEnd()) {
49 65 QBoxSet *set = dataReader.readBox();
50 66 if (set)
51 series->append(set);
67 boxWhiskSeries->append(set);
52 68 }
53
54 69 //![3]
70
71 //! [4]
55 72 QChart *chart = new QChart();
56 chart->addSeries(series);
57 chart->setTitle("Acme's share deviation in 2012");
73 chart->addSeries(acmeSeries);
74 chart->addSeries(boxWhiskSeries);
75 chart->setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012");
58 76 chart->setAnimationOptions(QChart::SeriesAnimations);
59 //![3]
60
61 77 //![4]
78
79 //! [5]
62 80 chart->createDefaultAxes();
63 81 chart->axisY()->setMin(15.0);
64 //![4]
65
82 chart->axisY()->setMax(34.0);
66 83 //![5]
84
85 //! [6]
67 86 chart->legend()->setVisible(true);
68 87 chart->legend()->setAlignment(Qt::AlignBottom);
69 //![5]
70
71 88 //![6]
89
90 //! [7]
72 91 QChartView *chartView = new QChartView(chart);
73 92 chartView->setRenderHint(QPainter::Antialiasing);
74 //![6]
75
76 93 //![7]
94
95 //! [8]
77 96 QMainWindow window;
78 97 window.setCentralWidget(chartView);
79 window.resize(600, 400);
98 window.resize(800, 600);
80 99 window.show();
81 //![7]
100 //! [8]
82 101
83 102 return a.exec();
84 103 }
@@ -123,15 +123,6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
123 123 */
124 124
125 125 /*!
126 \fn void QBoxSet::colorChanged(QColor)
127 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
128 */
129 /*!
130 \qmlsignal BoxSet::onColorChanged(QColor color)
131 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
132 */
133
134 /*!
135 126 \fn void QBoxSet::valuesChanged()
136 127 This signal is emitted when multiple values have been changed on the box-and-whisker item.
137 128 \sa append()
General Comments 0
You need to be logged in to leave comments. Login now