##// END OF EJS Templates
New test added to BarModelMapper
New test added to BarModelMapper

File last commit:

r1415:3a9150ae63dc
r1436:aaa0b338ff38
Show More
examples-stackedbarchartdrilldown.qdoc
45 lines | 2.8 KiB | text/plain | TextLexer
/ doc / src / examples-stackedbarchartdrilldown.qdoc
/*!
\example examples/stackedbarchartdrilldown
\title StackedBarChart Drilldown Example
\subtitle
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:
\image examples_stackedbarchartdrilldown1.png
Mouse button clicked on a month, shows the harvest from that month:
\image examples_stackedbarchartdrilldown2.png
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.
\snippet ../examples/stackedbarchartdrilldown/drilldownseries.h 1
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
Now we have our drilldown classes and we can start using them.
First create the chart.
\snippet ../examples/stackedbarchartdrilldown/main.cpp 1
We define categories, from wich the drilldown series will be constructed.
\snippet ../examples/stackedbarchartdrilldown/main.cpp 2
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.
To make mapping work, we connect the clicked signals from our series to the drilldownChart.
\snippet ../examples/stackedbarchartdrilldown/main.cpp 3
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.
\snippet ../examples/stackedbarchartdrilldown/main.cpp 4
Here we set the chart to show top level series initially.
\snippet ../examples/stackedbarchartdrilldown/main.cpp 5
*/