Tracking data indexes in Datasets

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
d3ik
Posts: 2
Joined: Thu Jan 26, 2006 10:55 pm

Tracking data indexes in Datasets

Post by d3ik » Wed Feb 08, 2006 7:07 pm

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.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Feb 09, 2006 12:27 pm

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

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

anxt
Posts: 1
Joined: Wed Sep 02, 2009 9:10 pm
antibot: No, of course not.

Re: Tracking data indexes in Datasets

Post by anxt » Wed Sep 02, 2009 9:54 pm

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.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Tracking data indexes in Datasets

Post by paradoxoff » Fri Sep 04, 2009 6:17 pm

anxt wrote: Do I have to change DefaultCategoryDataset? How?
Is there anyone can help me by a concrete example?
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 methods

Code: Select all

addAdditionalValue(double value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)
getAdditionalValue(java.lang.Comparable rowKey, java.lang.Comparable columnKey)
to a class DefaultCategoryDatasetWithAdditionalValue.
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.

Locked