MultiLevel DrillDownPieChart in less then 30min as component for TableViews

The full code and demo jUnit you will find under : BitBucket Repo - RapidPM - Modules - javafx-chart-pie-drilldown 
Please use the develop branch and a commit after 265b5f5 

Sometimes you want to have a drill down pi chart for a tableview. This code often looks like the following
(example from the oracle side)
image

What you can see, is the direct way of putting the data together for each drilldown-level.
But if you want to drill down more than one level.. the code will be long.
For this example I am using the following demo data table.

image
What I want to reach is a short way for a developer to aggregate from one row to an other (in both directions)
Here the pie–chart for this demo data and clicking the following steps:
Rows: Vorname->Nachname->Datum->Betrag
Data: Holger->Hoppel->2013.10.01->122.0
imageimageimageimage
You can see, that for each level you will get the aggregated data from the table..  But how to do it?
The basic is the Aggregator-Class

With this you can aggregate a collection to a map. The key is the aggregated value from the collection elements.
For this example: A Collection of the TransientDemoDataRow (Collection) aggregated over the attribute vorname.
With our demo data table you will get a map with two collections.
a) Holger –> List of 6 elements
b) Willi –> List of 4 elements
This is the data for the first level of the DrillDownPieChart. (first pic of the pie charts see above)
For our DrillDownPieChart we are using the following aggregator extending the MapAggregator.


We are holding the reference to the next level aggregator and the reference to the parent aggregator.
To implement the aggregator for each col. we want to use for our DrillDownPieChart we have to write code like the following

The method getLevelName is to label the PieChart for the user.
The method getKeyElement is the value used for the aggregation.
The method aggregateValue is to calculate the double, used by the pie chart as value.
After this you have to put all together… the logic-part is done now..
The gui part looks like this: Extending the DrillDownPieChart with the type you need as data holder, here the TransientDemoDataRow.
and putting it to a fxml file.
ready… 

The steps for a developer are:
1) writing the transient data holder for an row –> TransientDemoDataRow
2) extending the DrillDownPieChart –> DemoDrillDownPieChart extends
3) extending the DrillDownPieChartMapAggregator –> NachnameAggregator extends DrillDownPieChartMapAggregator
4) putting all aggregator implementations together –> Controller – Class
5) add the element to the fxml file,
6) init() and ready
For a normal TableView with a handfull of rows you will need less than 30 min.

The basic classes to use for an developer:
image

All classes from the jUnit demo available at the javafx-chart-pie-drilldown module.
image

Kommentare

Beliebte Posts