##// END OF EJS Templates
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
sauimone -
r1208:2943560d5819
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,40
1 /*!
2 \example examples/groupedbarchart
3 \title GroupedBarChart Example
4 \subtitle
5
6 The example shows how to create simple bar chart. GroupedBarChart shows the data in sets as separate bars, which are grouped in categories.
7
8 \image examples_groupedbarchart.png
9
10 First we define categories.
11
12 \snippet ../examples/groupedbarchart/main.cpp 1
13
14 Data that groupedbarchart visualizes, is defined by QBarSet instances. Here we create some sets and append data
15 we want to visualize to them.
16
17 \snippet ../examples/groupedbarchart/main.cpp 2
18
19 To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating
20 the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets
21 are added to series here.
22
23 \snippet ../examples/groupedbarchart/main.cpp 3
24
25 Then we create a chart and add the series to it.
26
27 \snippet ../examples/groupedbarchart/main.cpp 4
28
29 And we also want to show the legend, so that the data is easier to read.
30
31 \snippet ../examples/groupedbarchart/main.cpp 5
32
33 Finally we add the chart onto a view.
34
35 \snippet ../examples/groupedbarchart/main.cpp 6
36
37 And it is ready to be shown in a window.
38
39 \snippet ../examples/groupedbarchart/main.cpp 7
40 */
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -3,38 +3,32
3 \title BarChart Example
3 \title BarChart Example
4 \subtitle
4 \subtitle
5
5
6 The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are grouped in categories.
6 The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are drawn at the x-axis to the position defined by data.
7
7
8 \image examples_barchart.png
8 \image examples_barchart.png
9
9
10 First we define categories.
10 Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data
11 we want to visualize to them. Note that first and third QPointF in each set have smaller intervals at their x coordinates. This will be reflected in the chart.
11
12
12 \snippet ../examples/barchart/main.cpp 1
13 \snippet ../examples/barchart/main.cpp 1
13
14
14 Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data
15 To combine the sets to a chart, we need to create QBarSeries instance. Then we append our barsets to the series.
15 we want to visualize to them.
16
16
17 \snippet ../examples/barchart/main.cpp 2
17 \snippet ../examples/barchart/main.cpp 2
18
19 To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating
20 the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets
21 are added to series here.
22
23 \snippet ../examples/barchart/main.cpp 3
24
18
25 Then we create a chart and add the series to it.
19 Next we create a chart and add the series to it.
26
20
27 \snippet ../examples/barchart/main.cpp 4
21 \snippet ../examples/barchart/main.cpp 3
28
22
29 And we also want to show the legend, so that the data is easier to read.
23 We want to have the legend displayed at the bottom of the chart. Also we turn on the nice numbers algorithm on for y-axis.
30
24
31 \snippet ../examples/barchart/main.cpp 5
25 \snippet ../examples/barchart/main.cpp 4
32
26
33 Finally we add the chart onto a view.
27 Finally we add the chart onto a view.
34
28
35 \snippet ../examples/barchart/main.cpp 6
29 \snippet ../examples/barchart/main.cpp 5
36
30
37 And it is ready to be shown in a window.
31 And it is ready to be shown in a window.
38
32
39 \snippet ../examples/percentbarchart/main.cpp 7
33 \snippet ../examples/percentbarchart/main.cpp 6
40 */
34 */
@@ -16,6 +16,7
16 <li><a href="examples-areachart.html">Area chart</a></li>
16 <li><a href="examples-areachart.html">Area chart</a></li>
17 <li><a href="examples-barchart.html">Bar chart</a></li>
17 <li><a href="examples-barchart.html">Bar chart</a></li>
18 <li><a href="examples-customchart.html">Custom chart</a></li>
18 <li><a href="examples-customchart.html">Custom chart</a></li>
19 <li><a href="examples-groupedbarchart.html">Grouped bar chart</a></li>
19 <li><a href="examples-linechart.html">Line chart</a></li>
20 <li><a href="examples-linechart.html">Line chart</a></li>
20 <li><a href="examples-modeldata.html">Model data</a></li>
21 <li><a href="examples-modeldata.html">Model data</a></li>
21 <li><a href="examples-percentbarchart.html">Percent bar chart</a></li>
22 <li><a href="examples-percentbarchart.html">Percent bar chart</a></li>
@@ -24,19 +24,20
24 <td><a href="examples-barchart.html"><img src="images/examples_barchart.png" width="440" alt="barchart" /></a></td>
24 <td><a href="examples-barchart.html"><img src="images/examples_barchart.png" width="440" alt="barchart" /></a></td>
25 </tr>
25 </tr>
26 <tr>
26 <tr>
27 <td><a href="examples-groupedbarchart.html"><img src="images/examples_groupedbarchart.png" width="440" alt="groupedbarcchart" /></a></td>
27 <td><a href="examples-stackedbarchart.html"><img src="images/examples_stackedbarchart.png" width="440" alt="stackedbarchart" /></a></td>
28 <td><a href="examples-stackedbarchart.html"><img src="images/examples_stackedbarchart.png" width="440" alt="stackedbarchart" /></a></td>
28 <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="440" alt="percentbarcchart" /></a></td>
29 </tr>
29 </tr>
30 <tr>
30 <tr>
31 <td><a href="examples-percentbarchart.html"><img src="images/examples_percentbarchart.png" width="440" alt="percentbarcchart" /></a></td>
31 <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="440" alt="linechart" /></a></td>
32 <td><a href="examples-splinechart.html"><img src="images/examples_splinechart.png" width="440" alt="linechart" /></a></td>
32 <td><a href="examples-piechart.html"><img src="images/examples_piechart.png" width="440" alt="piechart" /></a></td>
33 </tr>
33 </tr>
34 <tr>
34 <tr>
35 <td><a href="examples-customchart.html"><img src="images/examples_customchart.png" width="440" alt="customerchart" /></a></td>
35 <td><a href="examples-customchart.html"><img src="images/examples_customchart.png" width="440" alt="customerchart" /></a></td>
36 <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart2.png" width="440" alt="zoomlinechart" /></a></td>
36 <td><a href="examples-piechart.html"><img src="images/examples_piechart.png" width="440" alt="piechart" /></a></td>
37 </tr>
37 </tr>
38 <tr>
38 <tr>
39 <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width=440 alt="charttheme" /></a></td>
39 <td><a href="demos-chartthemes.html"><img src="images/demo_chartthemes_blue_cerulean.png" width=440 alt="charttheme" /></a></td>
40 <td><a href="examples-zoomlinechart.html"><img src="images/examples_zoomlinechart2.png" width="440" alt="zoomlinechart" /></a></td>
40 </tr>
41 </tr>
41 </table>
42 </table>
42 </div>
43 </div>
@@ -32,11 +32,6 int main(int argc, char *argv[])
32 QApplication a(argc, argv);
32 QApplication a(argc, argv);
33
33
34 //![1]
34 //![1]
35 QBarCategories categories;
36 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
37 //![1]
38
39 //![2]
40 QBarSet *set0 = new QBarSet("Jane");
35 QBarSet *set0 = new QBarSet("Jane");
41 QBarSet *set1 = new QBarSet("John");
36 QBarSet *set1 = new QBarSet("John");
42 QBarSet *set2 = new QBarSet("Axel");
37 QBarSet *set2 = new QBarSet("Axel");
@@ -48,42 +43,40 int main(int argc, char *argv[])
48 *set2 << QPointF(0.2, 3) << QPointF(1.4, 4) << QPointF(2.50, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8);
43 *set2 << QPointF(0.2, 3) << QPointF(1.4, 4) << QPointF(2.50, 5) << QPointF(3.4, 6) << QPointF(4.4, 7) << QPointF(5.4, 8);
49 *set3 << QPointF(0.3, 4) << QPointF(1.6, 5) << QPointF(2.55, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9);
44 *set3 << QPointF(0.3, 4) << QPointF(1.6, 5) << QPointF(2.55, 6) << QPointF(3.6, 7) << QPointF(4.6, 8) << QPointF(5.6, 9);
50 *set4 << QPointF(0.4, 5) << QPointF(1.8, 6) << QPointF(2.6, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10);
45 *set4 << QPointF(0.4, 5) << QPointF(1.8, 6) << QPointF(2.6, 7) << QPointF(3.8, 8) << QPointF(4.8, 9) << QPointF(5.8, 10);
51 //![2]
46 //![1]
52
47
53 //![3]
48 //![2]
54 QBarSeries* series = new QBarSeries();
49 QBarSeries* series = new QBarSeries();
55 series->setCategories(categories);
56 series->append(set0);
50 series->append(set0);
57 series->append(set1);
51 series->append(set1);
58 series->append(set2);
52 series->append(set2);
59 series->append(set3);
53 series->append(set3);
60 series->append(set4);
54 series->append(set4);
55 //![2]
61
56
62 //![3]
57 //![3]
63
64 //![4]
65 QChart* chart = new QChart();
58 QChart* chart = new QChart();
66 chart->addSeries(series);
59 chart->addSeries(series);
67 chart->setTitle("Simple barchart example");
60 chart->setTitle("Simple barchart example");
68 //![4]
61 //![3]
69
62
70 //![5]
63 //![4]
71 chart->legend()->setVisible(true);
64 chart->legend()->setVisible(true);
72 chart->legend()->setAlignment(QLegend::AlignmentBottom);
65 chart->legend()->setAlignment(QLegend::AlignmentBottom);
73 chart->axisY()->setNiceNumbersEnabled(true);
66 chart->axisY()->setNiceNumbersEnabled(true);
74 //![5]
67 //![4]
75
68
76 //![6]
69 //![5]
77 QChartView* chartView = new QChartView(chart);
70 QChartView* chartView = new QChartView(chart);
78 chartView->setRenderHint(QPainter::Antialiasing);
71 chartView->setRenderHint(QPainter::Antialiasing);
79 //![6]
72 //![5]
80
73
81 //![7]
74 //![6]
82 QMainWindow window;
75 QMainWindow window;
83 window.setCentralWidget(chartView);
76 window.setCentralWidget(chartView);
84 window.resize(400, 300);
77 window.resize(400, 300);
85 window.show();
78 window.show();
86 //![7]
79 //![6]
87
80
88 return a.exec();
81 return a.exec();
89 }
82 }
@@ -39,9 +39,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 \brief part of QtCommercial chart API.
39 \brief part of QtCommercial chart API.
40 \mainclass
40 \mainclass
41
41
42 QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple
42 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
43 QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined
43 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
44 by QStringList.
44 and y-value is the height of the bar. The category names are ignored with this series and x-axis
45 shows the x-values.
45
46
46 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
47 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
47 \image examples_barchart.png
48 \image examples_barchart.png
@@ -65,11 +66,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
65 */
66 */
66
67
67 /*!
68 /*!
68 Constructs empty QBarSeries. Parameter \a categories defines the categories for chart.
69 Constructs empty QBarSeries.
69 QBarSeries is QObject which is a child of a \a parent.
70 QBarSeries is QObject which is a child of a \a parent.
70 */
71 */
71 QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) :
72 QBarSeries::QBarSeries(QObject *parent) :
72 QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent)
73 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
73 {
74 {
74 }
75 }
75
76
@@ -97,6 +98,9 QAbstractSeries::SeriesType QBarSeries::type() const
97 return QAbstractSeries::SeriesTypeBar;
98 return QAbstractSeries::SeriesTypeBar;
98 }
99 }
99
100
101 /*!
102 Sets the \a categories, which are used to to group the data.
103 */
100 void QBarSeries::setCategories(QBarCategories categories)
104 void QBarSeries::setCategories(QBarCategories categories)
101 {
105 {
102 Q_D(QBarSeries);
106 Q_D(QBarSeries);
@@ -105,7 +109,9 void QBarSeries::setCategories(QBarCategories categories)
105 }
109 }
106
110
107 /*!
111 /*!
108 Adds a set of bars to series. Takes ownership of \a set.
112 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
113 Returns true, if appending succeeded.
114
109 */
115 */
110 bool QBarSeries::append(QBarSet *set)
116 bool QBarSeries::append(QBarSet *set)
111 {
117 {
@@ -122,6 +128,7 bool QBarSeries::append(QBarSet *set)
122
128
123 /*!
129 /*!
124 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
130 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
131 Returns true, if set was removed.
125 */
132 */
126 bool QBarSeries::remove(QBarSet *set)
133 bool QBarSeries::remove(QBarSet *set)
127 {
134 {
@@ -138,6 +145,9 bool QBarSeries::remove(QBarSet *set)
138
145
139 /*!
146 /*!
140 Adds a list of barsets to series. Takes ownership of \a sets.
147 Adds a list of barsets to series. Takes ownership of \a sets.
148 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
149 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
150 and function returns false.
141 */
151 */
142 bool QBarSeries::append(QList<QBarSet* > sets)
152 bool QBarSeries::append(QList<QBarSet* > sets)
143 {
153 {
@@ -198,7 +208,7 int QBarSeries::barsetCount() const
198 int QBarSeries::categoryCount() const
208 int QBarSeries::categoryCount() const
199 {
209 {
200 Q_D(const QBarSeries);
210 Q_D(const QBarSeries);
201 return d->m_categories.count();
211 return d->categoryCount();
202 }
212 }
203
213
204 /*!
214 /*!
@@ -276,7 +286,7 QBarModelMapper* QBarSeries::modelMapper() const
276 QBarCategories QBarSeries::categories() const
286 QBarCategories QBarSeries::categories() const
277 {
287 {
278 Q_D(const QBarSeries);
288 Q_D(const QBarSeries);
279 return d->m_categories;
289 return d->categories();
280 }
290 }
281
291
282 /*!
292 /*!
@@ -295,7 +305,6 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
295 QAbstractSeriesPrivate(q),
305 QAbstractSeriesPrivate(q),
296 m_barMargin(0.05), // Default value is 5% of category width
306 m_barMargin(0.05), // Default value is 5% of category width
297 m_mapper(0)
307 m_mapper(0)
298 // m_categories(categories),
299 {
308 {
300 }
309 }
301
310
@@ -304,6 +313,51 void QBarSeriesPrivate::setCategories(QBarCategories categories)
304 m_categories = categories;
313 m_categories = categories;
305 }
314 }
306
315
316 void QBarSeriesPrivate::insertCategory(int index, const QString category)
317 {
318 m_categories.insert(index, category);
319 emit categoriesUpdated();
320 }
321
322 void QBarSeriesPrivate::removeCategory(int index)
323 {
324 m_categories.removeAt(index);
325 emit categoriesUpdated();
326 }
327
328 int QBarSeriesPrivate::categoryCount() const
329 {
330 if (m_categories.count() > 0) {
331 return m_categories.count();
332 }
333
334 // No categories defined. return count of longest set.
335 int count = 0;
336 for (int i=0; i<m_barSets.count(); i++) {
337 if (m_barSets.at(i)->count() > count) {
338 count = m_barSets.at(i)->count();
339 }
340 }
341
342 return count;
343 }
344
345 QBarCategories QBarSeriesPrivate::categories() const
346 {
347 if (m_categories.count() > 0) {
348 return m_categories;
349 }
350
351 // No categories defined. retun list of indices.
352 QBarCategories categories;
353
354 int count = categoryCount();
355 for (int i = 0; i < count; i++) {
356 categories.append(QString::number(i));
357 }
358 return categories;
359 }
360
307 void QBarSeriesPrivate::setBarMargin(qreal margin)
361 void QBarSeriesPrivate::setBarMargin(qreal margin)
308 {
362 {
309 if (margin > 1.0) {
363 if (margin > 1.0) {
@@ -328,7 +382,11 QBarSet* QBarSeriesPrivate::barsetAt(int index)
328
382
329 QString QBarSeriesPrivate::categoryName(int category)
383 QString QBarSeriesPrivate::categoryName(int category)
330 {
384 {
331 return m_categories.at(category);
385 if ((category > 0) && (category < m_categories.count())) {
386 return m_categories.at(category);
387 }
388
389 return QString::number(category);
332 }
390 }
333
391
334 qreal QBarSeriesPrivate::min()
392 qreal QBarSeriesPrivate::min()
@@ -425,7 +483,7 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
425 qreal QBarSeriesPrivate::maxCategorySum()
483 qreal QBarSeriesPrivate::maxCategorySum()
426 {
484 {
427 qreal max = INT_MIN;
485 qreal max = INT_MIN;
428 int count = m_categories.count();
486 int count = categoryCount();
429 for (int i = 0; i < count; i++) {
487 for (int i = 0; i < count; i++) {
430 qreal sum = categorySum(i);
488 qreal sum = categorySum(i);
431 if (sum > max)
489 if (sum > max)
@@ -540,18 +598,6 void QBarSeriesPrivate::initializeDataFromModel()
540 // emit updatedBars();
598 // emit updatedBars();
541 }
599 }
542
600
543 void QBarSeriesPrivate::insertCategory(int index, const QString category)
544 {
545 m_categories.insert(index, category);
546 emit categoriesUpdated();
547 }
548
549 void QBarSeriesPrivate::removeCategory(int index)
550 {
551 m_categories.removeAt(index);
552 emit categoriesUpdated();
553 }
554
555 void QBarSeriesPrivate::barsetChanged()
601 void QBarSeriesPrivate::barsetChanged()
556 {
602 {
557 emit updatedBars();
603 emit updatedBars();
@@ -566,7 +612,7 void QBarSeriesPrivate::scaleDomain(Domain& domain)
566 int tickXCount(domain.tickXCount());
612 int tickXCount(domain.tickXCount());
567 int tickYCount(domain.tickYCount());
613 int tickYCount(domain.tickYCount());
568
614
569 qreal x = m_categories.count();
615 qreal x = categoryCount();
570 qreal y = max();
616 qreal y = max();
571 minX = qMin(minX, x);
617 minX = qMin(minX, x);
572 minY = qMin(minY, y);
618 minY = qMin(minY, y);
@@ -46,8 +46,8 public:
46 QAbstractSeries::SeriesType type() const;
46 QAbstractSeries::SeriesType type() const;
47 void setCategories(QBarCategories categories);
47 void setCategories(QBarCategories categories);
48
48
49 bool append(QBarSet *set); // Takes ownership of set
49 bool append(QBarSet *set);
50 bool remove(QBarSet *set); // Releases ownership, doesn't delete set
50 bool remove(QBarSet *set);
51 bool append(QList<QBarSet* > sets);
51 bool append(QList<QBarSet* > sets);
52 bool remove(QList<QBarSet* > sets);
52 bool remove(QList<QBarSet* > sets);
53 int barsetCount() const;
53 int barsetCount() const;
@@ -19,6 +19,11 class QBarSeriesPrivate : public QAbstractSeriesPrivate
19 public:
19 public:
20 QBarSeriesPrivate(QBarSeries *parent);
20 QBarSeriesPrivate(QBarSeries *parent);
21 void setCategories(QBarCategories categories);
21 void setCategories(QBarCategories categories);
22 void insertCategory(int index, const QString category);
23 void removeCategory(int index);
24 int categoryCount() const;
25 QBarCategories categories() const;
26
22 void setBarMargin(qreal margin);
27 void setBarMargin(qreal margin);
23 qreal barMargin();
28 qreal barMargin();
24
29
@@ -26,9 +31,6 public:
26 Chart* createGraphics(ChartPresenter* presenter);
31 Chart* createGraphics(ChartPresenter* presenter);
27 QList<LegendMarker*> createLegendMarker(QLegend* legend);
32 QList<LegendMarker*> createLegendMarker(QLegend* legend);
28
33
29 void insertCategory(int index, const QString category);
30 void removeCategory(int index);
31
32 QBarSet* barsetAt(int index);
34 QBarSet* barsetAt(int index);
33 QString categoryName(int category);
35 QString categoryName(int category);
34 qreal min();
36 qreal min();
@@ -34,7 +34,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 \mainclass
35 \mainclass
36
36
37 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39
39
40 /*!
40 /*!
@@ -84,13 +84,22 QString QBarSet::name() const
84 return d_ptr->m_name;
84 return d_ptr->m_name;
85 }
85 }
86
86
87 /*!
88 Appends a point to set. Parameter \a value x coordinate defines the
89 position in x-axis and y coordinate defines the height of bar.
90 Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
91 the x values are used or ignored.
92 */
87 void QBarSet::append(const QPointF value)
93 void QBarSet::append(const QPointF value)
88 {
94 {
89 d_ptr->m_values.append(value);
95 d_ptr->m_values.append(value);
90 emit d_ptr->restructuredBars();
96 emit d_ptr->restructuredBars();
91 }
97 }
92
98
93
99 /*!
100 Appends a list of \a points to set. Works like append with single point.
101 \sa append()
102 */
94 void QBarSet::append(const QList<QPointF> values)
103 void QBarSet::append(const QList<QPointF> values)
95 {
104 {
96 for (int i=0; i<values.count(); i++) {
105 for (int i=0; i<values.count(); i++) {
@@ -100,15 +109,19 void QBarSet::append(const QList<QPointF> values)
100 }
109 }
101
110
102 /*!
111 /*!
103 Appends new value \a value to the end of set.
112 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
113 with x coordinate being the index of appended value and y coordinate is the value.
104 */
114 */
105 void QBarSet::append(const qreal value)
115 void QBarSet::append(const qreal value)
106 {
116 {
107 append(QPointF(d_ptr->m_values.count(), value));
117 append(QPointF(d_ptr->m_values.count(), value));
108 // d_ptr->m_values.append(value);
109 }
118 }
110
119
111
120 /*!
121 Appends a list of reals to set. Works like append with single real value. The values in list
122 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
123 \sa append()
124 */
112 void QBarSet::append(const QList<qreal> values)
125 void QBarSet::append(const QList<qreal> values)
113 {
126 {
114 int index = d_ptr->m_values.count();
127 int index = d_ptr->m_values.count();
@@ -120,7 +133,8 void QBarSet::append(const QList<qreal> values)
120 }
133 }
121
134
122 /*!
135 /*!
123 Appends new value \a value to the end of set.
136 Convinience operator. Same as append, with real \a value.
137 \sa append()
124 */
138 */
125 QBarSet& QBarSet::operator << (const qreal &value)
139 QBarSet& QBarSet::operator << (const qreal &value)
126 {
140 {
@@ -128,6 +142,10 QBarSet& QBarSet::operator << (const qreal &value)
128 return *this;
142 return *this;
129 }
143 }
130
144
145 /*!
146 Convinience operator. Same as append, with QPointF \a value.
147 \sa append()
148 */
131 QBarSet& QBarSet::operator << (const QPointF &value)
149 QBarSet& QBarSet::operator << (const QPointF &value)
132 {
150 {
133 append(value);
151 append(value);
@@ -165,7 +183,10 void QBarSet::replace(const int index, const qreal value)
165 }
183 }
166
184
167 /*!
185 /*!
168 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF
186 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
187 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
188 of the QPointF (if appended with QPointF append).
189 If the index is out of bounds QPointF(0, 0.0) is returned.
169 */
190 */
170 QPointF QBarSet::at(const int index) const
191 QPointF QBarSet::at(const int index) const
171 {
192 {
@@ -177,7 +198,9 QPointF QBarSet::at(const int index) const
177 }
198 }
178
199
179 /*!
200 /*!
180 Returns value of set indexed by \a index
201 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
202 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
203 of the QPointF (if appended with QPointF append).
181 */
204 */
182 QPointF QBarSet::operator [](const int index) const
205 QPointF QBarSet::operator [](const int index) const
183 {
206 {
@@ -193,7 +216,7 int QBarSet::count() const
193 }
216 }
194
217
195 /*!
218 /*!
196 Returns sum of all values in barset.
219 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
197 */
220 */
198 qreal QBarSet::sum() const
221 qreal QBarSet::sum() const
199 {
222 {
@@ -32,9 +32,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
33 \mainclass
33 \mainclass
34
34
35 QGroupedBarSeries represents a series of data shown as bars. All bars in same category are
35 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 grouped next to each other. One QGroupedBarSeries can contain multiple QBarSet data sets.
36 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
37 QGroupedBarSeries groups the data from sets to categories, which are defined by QStringList.
37 from sets to categories, which are defined by a QStringList.
38
38
39 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
39 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
40 \image examples_groupedbarchart.png
40 \image examples_groupedbarchart.png
@@ -45,11 +45,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45 /*!
45 /*!
46 \fn virtual QSeriesType QGroupedBarSeries::type() const
46 \fn virtual QSeriesType QGroupedBarSeries::type() const
47 \brief Returns type of series.
47 \brief Returns type of series.
48 \sa QSeriesType
48 \sa QAbstractSeries, QSeriesType
49 */
49 */
50
50
51 /*!
51 /*!
52 Constructs empty QGroupedBarSeries. Parameter \a categories defines the categories for chart.
52 Constructs empty QGroupedBarSeries.
53 QGroupedBarSeries is QObject which is a child of a \a parent.
53 QGroupedBarSeries is QObject which is a child of a \a parent.
54 */
54 */
55 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
55 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
@@ -25,7 +25,6
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
29
31 /*!
30 /*!
@@ -33,9 +32,9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
34 \mainclass
33 \mainclass
35
34
36 QPercentBarSeries represents a series of data shown as bars. Each bar of QBarSet is shown as percentage
35 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 of all bars in category. One QPercentBarSeries can contain multiple QBarSet data sets.
36 as stacks, where each bar is shown as percentage of all bars in that category.
38 QBarSeries groups the data from sets to categories, which are defined by QStringList.
37 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
39
38
40 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
39 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
41 \image examples_percentbarchart.png
40 \image examples_percentbarchart.png
@@ -50,11 +49,11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50 */
49 */
51
50
52 /*!
51 /*!
53 Constructs empty QPercentBarSeries. Parameter \a categories defines the categories for chart.
52 Constructs empty QPercentBarSeries.
54 QPercentBarSeries is QObject which is a child of a \a parent.
53 QPercentBarSeries is QObject which is a child of a \a parent.
55 */
54 */
56 QPercentBarSeries::QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent)
55 QPercentBarSeries::QPercentBarSeries(QObject *parent)
57 : QBarSeries(*new QPercentBarSeriesPrivate(/*categories,*/this), parent)
56 : QBarSeries(*new QPercentBarSeriesPrivate(this), parent)
58 {
57 {
59 }
58 }
60
59
@@ -65,7 +64,7 QAbstractSeries::SeriesType QPercentBarSeries::type() const
65
64
66 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67
66
68 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(/*QBarCategories categories,*/ QPercentBarSeries *q) : QBarSeriesPrivate(/*categories,*/q)
67 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q)
69 {
68 {
70
69
71 }
70 }
@@ -32,7 +32,7 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 public:
34 public:
35 explicit QPercentBarSeries(/*QBarCategories categories,*/ QObject *parent = 0);
35 explicit QPercentBarSeries(QObject *parent = 0);
36 QAbstractSeries::SeriesType type() const;
36 QAbstractSeries::SeriesType type() const;
37
37
38 private:
38 private:
@@ -32,8 +32,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
33 \mainclass
33 \mainclass
34
34
35 QStackedBarSeries represents a series of data shown as bars. All bars in same category are
35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 stacked on top of each other. One QStackedBarSeries can contain multiple QBarSet data sets.
36 as stacks, where bars in same category are stacked on top of each other.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
38
38
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
@@ -45,15 +45,15 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45 /*!
45 /*!
46 \fn virtual QSeriesType QStackedBarSeries::type() const
46 \fn virtual QSeriesType QStackedBarSeries::type() const
47 \brief Returns type of series.
47 \brief Returns type of series.
48 \sa QSeriesType
48 \sa QAbstractSeries, QSeriesType
49 */
49 */
50
50
51 /*!
51 /*!
52 Constructs empty QStackedBarSeries. Parameter \a categories defines the categories for chart.
52 Constructs empty QStackedBarSeries.
53 QStackedBarSeries is QObject which is a child of a \a parent.
53 QStackedBarSeries is QObject which is a child of a \a parent.
54 */
54 */
55 QStackedBarSeries::QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent)
55 QStackedBarSeries::QStackedBarSeries(QObject *parent)
56 : QBarSeries(*new QStackedBarSeriesPrivate(/*categories,*/this), parent)
56 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
57 {
57 {
58 }
58 }
59
59
@@ -64,7 +64,7 QAbstractSeries::SeriesType QStackedBarSeries::type() const
64
64
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66
66
67 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(/*QBarCategories categories,*/ QStackedBarSeries *q) : QBarSeriesPrivate(/*categories,*/q)
67 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
68 {
68 {
69
69
70 }
70 }
@@ -32,7 +32,7 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 public:
34 public:
35 explicit QStackedBarSeries(/*QBarCategories categories,*/ QObject *parent = 0);
35 explicit QStackedBarSeries(QObject *parent = 0);
36 QAbstractSeries::SeriesType type() const;
36 QAbstractSeries::SeriesType type() const;
37
37
38 private:
38 private:
@@ -88,6 +88,7 void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY)
88
88
89 series->d_ptr->scaleDomain(*domain);
89 series->d_ptr->scaleDomain(*domain);
90
90
91 // Note that with SeriesTypeBar we don't set up categories, but use real values on x-asis
91 if(series->type() == QAbstractSeries::SeriesTypeGroupedBar
92 if(series->type() == QAbstractSeries::SeriesTypeGroupedBar
92 || series->type() == QAbstractSeries::SeriesTypeStackedBar
93 || series->type() == QAbstractSeries::SeriesTypeStackedBar
93 || series->type() == QAbstractSeries::SeriesTypePercentBar) {
94 || series->type() == QAbstractSeries::SeriesTypePercentBar) {
@@ -44,6 +44,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44 \value SeriesTypeBar
44 \value SeriesTypeBar
45 \value SeriesTypeStackedBar
45 \value SeriesTypeStackedBar
46 \value SeriesTypePercentBar
46 \value SeriesTypePercentBar
47 \value SeriesTypeGroupedBar
47 \value SeriesTypePie
48 \value SeriesTypePie
48 \value SeriesTypeScatter
49 \value SeriesTypeScatter
49 \value SeriesTypeSpline
50 \value SeriesTypeSpline
General Comments 0
You need to be logged in to leave comments. Login now