I'm using JFreeChart to build drillable web reports (i.e. - click on a slice of a pie chart, it displays data relating to that slice).
Using PieChart3DDemo1.java as a reference, say I had a database table with rows for Visual Basic, Java, C/C++, PHP, Perl. In the PieDataset this becomes a key/value relationship: Visual Basic = 10, Java = 43.2, etc.
When I'm putting that into a URL to drill to details on, say Visual Basic, by default the URL generated would be something like "index.html?category=Visual%20Basic&pieIndex=0". That functions as intended, but in the drill down that would require a full text lookup for 'Visual Basic' in my database queries. What I would like to do is associate a third value (the row index for Visual Basic) so I can reference the value by index in the drill down page, making database queries significantly faster.
My first thought was to build my own PieDataset class with another key/value pair, but I had concerns about performance and memory usage. I was hoping that someone with more experience with JFC would be able to offer some guidance.
Tracking data indexes in Datasets
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Essentially you want to record two values for each key, the data value and the database row index. You can either write your own implementation of PieDataset to store both values, or use two DefaultPieDataset instances, one to store the data values and the other to store the row index values.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Re: Tracking data indexes in Datasets
Hi,
I'm working with BarChart and html building an image and a html-map.
Following one among examples found on web I am using:
DefaultCategoryDataset dataset = new DefaultCategoryDataset;
for..{
dataset.addValue(value1, serie1,firstParameter).
}
// Create the chart object
.....
BarRenderer renderer = new BarRenderer();
renderer.setItemURLGenerator(new StandardCategoryURLGenerator("index","serie","categoryA"));
....
So,each item of BarChart has this href="index?serie=serie1&categoryA=firstParameter"
I also would want add another parameter to request:
"index?serie=serie1&categoryA=firstParameter&categoryBname=secondParameter"
instead of
"index?serie=serie1&categoryA=firstParameter"
I have been able to change StandardCategoryURLGenerator in MyCategoryURLGenerator class and build any url but I have only serie1 and firstParameter in class MyCategoryURLGenerator. Each item should have another parameter.
Do I have to change DefaultCategoryDataset? How?
Is there anyone can help me by a concrete example?
Thank you.
I'm working with BarChart and html building an image and a html-map.
Following one among examples found on web I am using:
DefaultCategoryDataset dataset = new DefaultCategoryDataset;
for..{
dataset.addValue(value1, serie1,firstParameter).
}
// Create the chart object
.....
BarRenderer renderer = new BarRenderer();
renderer.setItemURLGenerator(new StandardCategoryURLGenerator("index","serie","categoryA"));
....
So,each item of BarChart has this href="index?serie=serie1&categoryA=firstParameter"
I also would want add another parameter to request:
"index?serie=serie1&categoryA=firstParameter&categoryBname=secondParameter"
instead of
"index?serie=serie1&categoryA=firstParameter"
I have been able to change StandardCategoryURLGenerator in MyCategoryURLGenerator class and build any url but I have only serie1 and firstParameter in class MyCategoryURLGenerator. Each item should have another parameter.
Do I have to change DefaultCategoryDataset? How?
Is there anyone can help me by a concrete example?
Thank you.
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: Tracking data indexes in Datasets
You better create your own CategoryDataset implementation that allows you to store the additional parameters that you need. Extending DefaultCategoryDataset would be the easiest way. Just add, e. g. the methodsanxt wrote: Do I have to change DefaultCategoryDataset? How?
Is there anyone can help me by a concrete example?
Code: Select all
addAdditionalValue(double value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)
getAdditionalValue(java.lang.Comparable rowKey, java.lang.Comparable columnKey)
Then, in the generateURL-method, check the type of the dataset, and if the dataset is an instance of DefaultCategoryDatasetWithAdditionalValue, call the getter.
The implementation should be straightforward, based on the freely available source code of DefaultCategoryDataset.