@@ -1,39 +1,39 | |||
|
1 | 1 | /*! |
|
2 | \example example/barchart | |
|
2 | \example examples/barchart | |
|
3 | 3 | \title BarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple bar chart. Barchart shows the data in sets as separate bars, which are grouped in categories. |
|
7 | 7 | |
|
8 | 8 | \image barchart.png |
|
9 | 9 | |
|
10 | 10 | First we define categories. |
|
11 | 11 | |
|
12 | \snippet ../example/barchart/main.cpp 1 | |
|
12 | \snippet ../examples/barchart/main.cpp 1 | |
|
13 | 13 | |
|
14 | 14 | Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data |
|
15 | 15 | we want to visulaize to them. |
|
16 | 16 | |
|
17 | \snippet ../example/barchart/main.cpp 2 | |
|
17 | \snippet ../examples/barchart/main.cpp 2 | |
|
18 | 18 | |
|
19 | 19 | To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating |
|
20 | 20 | the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets |
|
21 | 21 | are added to series here. |
|
22 | 22 | |
|
23 | \snippet ../example/barchart/main.cpp 3 | |
|
23 | \snippet ../examples/barchart/main.cpp 3 | |
|
24 | 24 | |
|
25 | 25 | We want our barchart to behave so, that when mouse is hovered over bar, the name of set which the bar |
|
26 | 26 | represents is shown as tooltip. |
|
27 | 27 | Also when we click the bar, floating values for the set are toggled. Floating values are the data values |
|
28 | 28 | that are drawn on top of bars. |
|
29 | 29 | |
|
30 | \snippet ../example/barchart/main.cpp 4 | |
|
30 | \snippet ../examples/barchart/main.cpp 4 | |
|
31 | 31 | |
|
32 | 32 | Here we create the view and add our series to it. Also we set the title and theme we want our chart to use |
|
33 | 33 | |
|
34 | \snippet ../example/barchart/main.cpp 5 | |
|
34 | \snippet ../examples/barchart/main.cpp 5 | |
|
35 | 35 | |
|
36 | 36 | For barchart, we don't need X-axis to be visible, so it can be disabled. |
|
37 | 37 | |
|
38 | \snippet ../example/barchart/main.cpp 6 | |
|
38 | \snippet ../examples/barchart/main.cpp 6 | |
|
39 | 39 | */ No newline at end of file |
@@ -1,39 +1,39 | |||
|
1 | 1 | /*! |
|
2 | \example example/percentbarchart | |
|
2 | \example examples/percentbarchart | |
|
3 | 3 | \title PercentBarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple percent bar chart. Percent bar chart shows the data in set as percentage of all sets, per category. |
|
7 | 7 | |
|
8 | 8 | \image percentbarchart.png |
|
9 | 9 | |
|
10 | 10 | First we define categories. |
|
11 | 11 | |
|
12 | \snippet ../example/percentbarchart/main.cpp 1 | |
|
12 | \snippet ../examples/percentbarchart/main.cpp 1 | |
|
13 | 13 | |
|
14 | 14 | Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data |
|
15 | 15 | we want to visulaize to them. |
|
16 | 16 | |
|
17 | \snippet ../example/percentbarchart/main.cpp 2 | |
|
17 | \snippet ../examples/percentbarchart/main.cpp 2 | |
|
18 | 18 | |
|
19 | 19 | To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating |
|
20 | 20 | the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets |
|
21 | 21 | are added to series here. |
|
22 | 22 | |
|
23 | \snippet ../example/percentbarchart/main.cpp 3 | |
|
23 | \snippet ../examples/percentbarchart/main.cpp 3 | |
|
24 | 24 | |
|
25 | 25 | We want our barchart to behave so, that when mouse is hovered over bar, the name of set which the bar |
|
26 | 26 | represents is shown as tooltip. |
|
27 | 27 | Also when we click the bar, floating values for the set are toggled. Floating values are the data values |
|
28 | 28 | that are drawn on top of bars. |
|
29 | 29 | |
|
30 | \snippet ../example/percentbarchart/main.cpp 4 | |
|
30 | \snippet ../examples/percentbarchart/main.cpp 4 | |
|
31 | 31 | |
|
32 | 32 | Here we create the view and add our series to it. Also we set the title and theme we want our chart to use |
|
33 | 33 | |
|
34 | \snippet ../example/percentbarchart/main.cpp 5 | |
|
34 | \snippet ../examples/percentbarchart/main.cpp 5 | |
|
35 | 35 | |
|
36 | 36 | For barchart, we don't need X-axis to be visible, so it can be disabled. |
|
37 | 37 | |
|
38 | \snippet ../example/percentbarchart/main.cpp 6 | |
|
38 | \snippet ../examples/percentbarchart/main.cpp 6 | |
|
39 | 39 | */ No newline at end of file |
@@ -1,42 +1,42 | |||
|
1 | 1 | /*! |
|
2 | \example example/stackedbarchartdrilldown | |
|
2 | \example examples/stackedbarchartdrilldown | |
|
3 | 3 | \title StackedBarChart Drilldown Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to implement drilldown using stacked barchart. In drilldown example we create stacked barchart, which shows the harvest of various chili peppers during season. In season view the harvest is grouped by month. To drill down to weekly view, user clicks selected month with right mouse button. On weekly view, the harvest of clicked month is shown by week. For example purposes each month is 4 weeks long :) |
|
7 | 7 | |
|
8 | 8 | Season view looks like this: |
|
9 | 9 | \image stackedbarchart_drilldown_season.png |
|
10 | 10 | |
|
11 | 11 | Right mouse button clicked on august, shows the harvest from august: |
|
12 | 12 | \image stackedbarchart_drilldown_august.png |
|
13 | 13 | |
|
14 | 14 | Here we define a drilldown series, which adds mapping for categories to other drilldown series. |
|
15 | 15 | Purpose of drilldown series is to contain knowledge of the drilldown structure. The mapDrilldownSeries function maps the category to given series. We can ask the mapping for category with drilldownSeries(QString category) function. |
|
16 | 16 | |
|
17 | \snippet ../example/stackedbarchartdrilldown/main.cpp 1 | |
|
17 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 1 | |
|
18 | 18 | |
|
19 | 19 | To enable drilldown we create own view, which implements handler for right click. All QBarSeries derived classes send out rightClicked(QBarSet*, QString) signal when series is clicked with right mouse button. The parameters QBarSet and QString contain the pointer to clicked bar set and name of category, where click occured. |
|
20 | 20 | |
|
21 | 21 | In our DrilldownChart we implement handler, which selects the drilldown chart with the category. |
|
22 | 22 | |
|
23 | \snippet ../example/stackedbarchartdrilldown/main.cpp 2 | |
|
23 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 2 | |
|
24 | 24 | |
|
25 | 25 | Here we define data, which we use to construct the chart. |
|
26 | 26 | |
|
27 | \snippet ../example/stackedbarchartdrilldown/main.cpp 3 | |
|
27 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 3 | |
|
28 | 28 | |
|
29 | 29 | To create the drilldown structure, we first create our top level series, which we call seasonSeries. For each month in seasonSeries we create a drilldown series, called weeklySeries which contains more detailed data for that month. |
|
30 | 30 | In weeklySeries, we use the drilldown handler to bring us back to seasonSeries. To do this we add mapping to the series. The seasonSeries is mapped to weeklySeries for each month. Every weeklySeries is mapped back to the seasonSeries. |
|
31 | 31 | To make mapping work, we connect the rightClicked signals from our series to the drilldownChart. |
|
32 | 32 | |
|
33 | \snippet ../example/stackedbarchartdrilldown/main.cpp 4 | |
|
33 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 4 | |
|
34 | 34 | |
|
35 | 35 | When we have our drilldown structure ready, we can add the data to it. Here we generate random crop for each plant in each week. The monthly crop is calculated from weekly crops. To enable floating values, we connect the clicked signal to toggle the value of corresponding set. |
|
36 | 36 | |
|
37 | \snippet ../example/stackedbarchartdrilldown/main.cpp 5 | |
|
37 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 5 | |
|
38 | 38 | |
|
39 | 39 | Here we set the chart to show top level series initially. |
|
40 | 40 | |
|
41 | \snippet ../example/stackedbarchartdrilldown/main.cpp 6 | |
|
41 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 6 | |
|
42 | 42 | */ No newline at end of file |
@@ -1,39 +1,39 | |||
|
1 | 1 | /*! |
|
2 | 2 | \example example/stackedbarchart |
|
3 | 3 | \title StackedBarChart Example |
|
4 | 4 | \subtitle |
|
5 | 5 | |
|
6 | 6 | The example shows how to create simple stacked bar chart. Stacked bar chart shows the data in sets as bars that are stacked on top of each other. The stacking is done per category. |
|
7 | 7 | |
|
8 | 8 | \image stackedbarchart.png |
|
9 | 9 | |
|
10 | 10 | First we define categories. |
|
11 | 11 | |
|
12 | \snippet ../example/stackedbarchart/main.cpp 1 | |
|
12 | \snippet ../examples/stackedbarchart/main.cpp 1 | |
|
13 | 13 | |
|
14 | 14 | Data that barchart visualizes, is defined by QBarSet instances. Here we create some sets and append data |
|
15 | 15 | we want to visulaize to them. |
|
16 | 16 | |
|
17 | \snippet ../example/stackedbarchart/main.cpp 2 | |
|
17 | \snippet ../examples/stackedbarchart/main.cpp 2 | |
|
18 | 18 | |
|
19 | 19 | To combine the sets and categories to a chart, we need to create QBarSeries instance. When creating |
|
20 | 20 | the QBarSeries, the categories must be known. Sets can be added later. For example purposes the sets |
|
21 | 21 | are added to series here. |
|
22 | 22 | |
|
23 | \snippet ../example/stackedbarchart/main.cpp 3 | |
|
23 | \snippet ../examples/stackedbarchart/main.cpp 3 | |
|
24 | 24 | |
|
25 | 25 | We want our barchart to behave so, that when mouse is hovered over bar, the name of set which the bar |
|
26 | 26 | represents is shown as tooltip. |
|
27 | 27 | Also when we click the bar, floating values for the set are toggled. Floating values are the data values |
|
28 | 28 | that are drawn on top of bars. |
|
29 | 29 | |
|
30 | \snippet ../example/stackedbarchart/main.cpp 4 | |
|
30 | \snippet ../examples/stackedbarchart/main.cpp 4 | |
|
31 | 31 | |
|
32 | 32 | Here we create the view and add our series to it. Also we set the title and theme we want our chart to use |
|
33 | 33 | |
|
34 | \snippet ../example/stackedbarchart/main.cpp 5 | |
|
34 | \snippet ../examples/stackedbarchart/main.cpp 5 | |
|
35 | 35 | |
|
36 | 36 | For barchart, we don't need X-axis to be visible, so it can be disabled. |
|
37 | 37 | |
|
38 | \snippet ../example/stackedbarchart/main.cpp 6 | |
|
38 | \snippet ../examples/stackedbarchart/main.cpp 6 | |
|
39 | 39 | */ No newline at end of file |
@@ -1,173 +1,175 | |||
|
1 | 1 | #include "qbarset.h" |
|
2 | 2 | #include <QDebug> |
|
3 | 3 | #include <QToolTip> |
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 | 7 | /*! |
|
8 | 8 | \class QBarSet |
|
9 | 9 | \brief part of QtCommercial chart API. |
|
10 | 10 | |
|
11 | 11 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
12 | 12 | First value of set is assumed to belong to first category, second to second category and so on. |
|
13 | 13 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
14 | 14 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
15 | 15 | |
|
16 | 16 | \mainclass |
|
17 | 17 | |
|
18 | 18 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
19 | 19 | */ |
|
20 | 20 | |
|
21 | 21 | /*! |
|
22 | 22 | \fn void QBarSet::clicked(QString category) |
|
23 | 23 | \brief signals that set has been clicked |
|
24 | 24 | Parameter \a category describes on which category was clicked |
|
25 | 25 | */ |
|
26 | 26 | |
|
27 | 27 | /*! |
|
28 | 28 | \fn void QBarSet::rightClicked(QString category) |
|
29 | 29 | \brief signals that set has been clicked with right mouse button |
|
30 | 30 | Parameter \a category describes on which category was clicked |
|
31 | 31 | */ |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
35 | 35 | \brief signals that mouse has entered over the set at position \a pos. |
|
36 | 36 | */ |
|
37 | 37 | |
|
38 | 38 | /*! |
|
39 | 39 | \fn void QBarSet::hoverLeave() |
|
40 | 40 | \brief signals that mouse has left from the set. |
|
41 | 41 | */ |
|
42 | 42 | |
|
43 | 43 | /*! |
|
44 | 44 | \fn void QBarSet::toggleFloatingValues() |
|
45 | 45 | \brief \internal |
|
46 | 46 | */ |
|
47 | 47 | |
|
48 | 48 | /*! |
|
49 | 49 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
50 | 50 | \brief \internal \a pos \a tip |
|
51 | 51 | */ |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
56 | 56 | */ |
|
57 | 57 | QBarSet::QBarSet(QString name, QObject *parent) |
|
58 | 58 | : QObject(parent) |
|
59 | 59 | ,mName(name) |
|
60 | 60 | { |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | Sets new \a name for set. |
|
65 | 65 | */ |
|
66 | 66 | void QBarSet::setName(QString name) |
|
67 | 67 | { |
|
68 | 68 | mName = name; |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | Returns name of the set. |
|
73 | 73 | */ |
|
74 | 74 | QString QBarSet::name() |
|
75 | 75 | { |
|
76 | 76 | return mName; |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | Appends new value \a value to the end of set. |
|
81 | 81 | */ |
|
82 | 82 | QBarSet& QBarSet::operator << (const qreal &value) |
|
83 | 83 | { |
|
84 | 84 | mValues.append(value); |
|
85 | 85 | return *this; |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | Returns count of values in set. |
|
90 | 90 | */ |
|
91 | 91 | int QBarSet::count() |
|
92 | 92 | { |
|
93 | 93 | return mValues.count(); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | Returns value of set indexed by \a index |
|
98 | 98 | */ |
|
99 | 99 | qreal QBarSet::valueAt(int index) |
|
100 | 100 | { |
|
101 | 101 | return mValues.at(index); |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | Sets a new value \a value to set, indexed by \a index |
|
106 | 106 | */ |
|
107 | 107 | void QBarSet::setValue(int index, qreal value) |
|
108 | 108 | { |
|
109 | 109 | mValues.replace(index,value); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | /*! | |
|
113 | Returns total sum of all values in barset. | |
|
114 | */ | |
|
112 | 115 | qreal QBarSet::total() |
|
113 | 116 | { |
|
114 | 117 | qreal total(0); |
|
115 | 118 | for (int i=0; i<mValues.count(); i++) { |
|
116 | 119 | total += mValues.at(i); |
|
117 | 120 | } |
|
118 | 121 | return total; |
|
119 | 122 | } |
|
120 | 123 | |
|
121 | ||
|
122 | 124 | /*! |
|
123 | 125 | Sets pen for set. Bars of this set are drawn using \a pen |
|
124 | 126 | */ |
|
125 | 127 | void QBarSet::setPen(const QPen pen) |
|
126 | 128 | { |
|
127 | 129 | mPen = pen; |
|
128 | 130 | } |
|
129 | 131 | |
|
130 | 132 | /*! |
|
131 | 133 | Returns pen of the set. |
|
132 | 134 | */ |
|
133 | 135 | QPen QBarSet::pen() const |
|
134 | 136 | { |
|
135 | 137 | return mPen; |
|
136 | 138 | } |
|
137 | 139 | |
|
138 | 140 | /*! |
|
139 | 141 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
140 | 142 | */ |
|
141 | 143 | void QBarSet::setBrush(const QBrush brush) |
|
142 | 144 | { |
|
143 | 145 | mBrush = brush; |
|
144 | 146 | } |
|
145 | 147 | |
|
146 | 148 | /*! |
|
147 | 149 | Returns brush of the set. |
|
148 | 150 | */ |
|
149 | 151 | QBrush QBarSet::brush() const |
|
150 | 152 | { |
|
151 | 153 | return mBrush; |
|
152 | 154 | } |
|
153 | 155 | |
|
154 | 156 | /*! |
|
155 | 157 | \internal \a pos |
|
156 | 158 | */ |
|
157 | 159 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
158 | 160 | { |
|
159 | 161 | emit showToolTip(pos, mName); |
|
160 | 162 | emit hoverEnter(pos); |
|
161 | 163 | } |
|
162 | 164 | |
|
163 | 165 | /*! |
|
164 | 166 | \internal |
|
165 | 167 | */ |
|
166 | 168 | void QBarSet::barHoverLeaveEvent() |
|
167 | 169 | { |
|
168 | 170 | // Emit signal to user of charts |
|
169 | 171 | emit hoverLeave(); |
|
170 | 172 | } |
|
171 | 173 | |
|
172 | 174 | #include "moc_qbarset.cpp" |
|
173 | 175 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now