examples-stackedbarchartdrilldown.qdoc
45 lines
| 2.8 KiB
| text/plain
|
TextLexer
Jani Honkonen
|
r919 | /*! | ||
\example examples/stackedbarchartdrilldown | ||||
Jani Honkonen
|
r920 | \title StackedBarChart Drilldown Example | ||
Jani Honkonen
|
r919 | \subtitle | ||
Jani Honkonen
|
r920 | 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 :) | ||
Season view looks like this: | ||||
Tero Ahola
|
r1411 | \image examples_stackedbarchartdrilldown1.png | ||
Jani Honkonen
|
r920 | |||
Tero Ahola
|
r1411 | Mouse button clicked on a month, shows the harvest from that month: | ||
\image examples_stackedbarchartdrilldown2.png | ||||
Jani Honkonen
|
r920 | |||
sauimone
|
r1415 | First we define a drilldown series class, which adds categories to stacked bar series and mapping for categories to other drilldown series. | ||
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(int category) function. | ||||
Jani Honkonen
|
r920 | |||
sauimone
|
r1415 | \snippet ../examples/stackedbarchartdrilldown/drilldownseries.h 1 | ||
Jani Honkonen
|
r920 | |||
sauimone
|
r1415 | Next we define our own drilldown chart, which implements handler for mouse click. All QBarSeries derived classes send out clicked(QBarSet*, int) signal when series is clicked with mouse. The parameter QBarSet contains pointer to clicked bar set and parameter int contains the index of clicked category. | ||
\snippet ../examples/stackedbarchartdrilldown/drilldownchart.h 1 | ||||
Jani Honkonen
|
r920 | |||
sauimone
|
r1415 | Now we have our drilldown classes and we can start using them. | ||
First create the chart. | ||||
\snippet ../examples/stackedbarchartdrilldown/main.cpp 1 | ||||
Jani Honkonen
|
r920 | |||
Jani Honkonen
|
r1940 | We define categories, from which the drilldown series will be constructed. | ||
sauimone
|
r1415 | |||
Jani Honkonen
|
r920 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 2 | ||
sauimone
|
r1415 | |||
Jani Honkonen
|
r920 | 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. | ||
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. | ||||
sauimone
|
r1415 | To make mapping work, we connect the clicked signals from our series to the drilldownChart. | ||
Jani Honkonen
|
r920 | |||
sauimone
|
r1415 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 3 | ||
Jani Honkonen
|
r920 | |||
sauimone
|
r1415 | 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 and is set as value to monthly series. | ||
Jani Honkonen
|
r920 | |||
sauimone
|
r1415 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 4 | ||
Jani Honkonen
|
r920 | |||
Here we set the chart to show top level series initially. | ||||
sauimone
|
r1415 | \snippet ../examples/stackedbarchartdrilldown/main.cpp 5 | ||
Jani Honkonen
|
r919 | */ | ||