KeyedValues2D and DefaultCategoryDataset

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Morwen
Posts: 26
Joined: Sat Apr 02, 2005 6:26 pm

KeyedValues2D and DefaultCategoryDataset

Post by Morwen » Sun Dec 10, 2006 4:12 pm

Hey everyone,

I noticed there was feature hiding in DefaultCategoryDataset's constructor.
DefaultKeyedValues2D allows us to set whether we want to sort the dataset according to key's values or not.

I think that ability should propogate to DefaultCategoryDataset's constructor as well (Optionally, of course), since there is no real workaround other than to recompile the project (there are other places which depend on DefaultCategoryDataset and are not hook-able).

Morwen.

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 » Tue Dec 12, 2006 4:26 pm

I plan to support this in the future, but it is a little tricky to implement, because it means that a series can change position in the dataset (for instance, when you add/insert an item with a new series key). That means the links to the series paint, stroke, shapes etc get lost (because those attributes are stored by index). The solution is either to store the attributes by series key (along the lines of the recent changes to the PiePlot class), or have the attributes reorder themselves in response to changes in the dataset. Both changes are significant pieces of work, and so far I haven't started on it.
David Gilbert
JFreeChart Project Leader

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

Morwen
Posts: 26
Joined: Sat Apr 02, 2005 6:26 pm

Post by Morwen » Tue Dec 12, 2006 7:00 pm

I'll read a bit more into it, maybe I can help with the time problem (And submit fixes through here?)

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Wed Jan 28, 2009 12:09 pm

Hi all!

Sorry to bring up this old topic again, but I have exactly the same problem: I want a DefaultCategoryDataset with sorted row keys but cannot use the DefaultCategoryDataset implementation as it hides the feature of sorted row keys, already supported by DefaultKeyedValues2D.

My row keys are sorted anyway, and the reason I want to set "sortRowKeys" to true is, to use the optimized algorithms in DefaultKeyedValues2D due to (significant) performance improvements. As my dataset won't change I don't think that I will face any of the problems mentioned by David.

Any comments?

- martin

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 » Wed Feb 04, 2009 3:17 pm

Would it be a problem to simply copy and paste the DefaultCategoryDataset source code into your own package, rename the class MyCategoryDataset, and change whatever you need to?

My comment from 12-Dec-2006 is still valid for this one, I think. I'd like to support this sorting (as has already been done for the DefaultPieDataset class)...but it means reworking the way the renderers reference paint and stroke attributes. And that is a big piece of work.
David Gilbert
JFreeChart Project Leader

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

matinh
Posts: 483
Joined: Fri Aug 11, 2006 10:08 am
Location: Austria

Post by matinh » Wed Feb 04, 2009 3:29 pm

Hi David!

Your suggestion is exactly what I currently do, and it works. However, it would be nice if this would be possible without overriding JFreeChart classes (maybe for others as well).

Maybe I just didn't get what problems you are facing. Changing the data from a DefaultCategoryDataset would eventually change the order of the data. But where's the problem here? If this happens rerendering a chart would be necessary anyway, wouldn't it? Thus, links to series paints and the like would have to be dropped and recalculated whenever a DatasetChanged event happened. Is this a problem?

Thanks for your answer anyway,
- martin

Locked