A discussion forum for JFreeChart (a 2D chart library for the Java platform).
-
zulfikaralib
- Posts: 14
- Joined: Thu Sep 22, 2005 5:38 am
- Location: Mumbai, India
-
Contact:
Post
by zulfikaralib » Thu Jun 11, 2009 12:32 pm
Hi All,
I was just wondering if it is possible to have a bar chart with two or more bars having the same name (labels in our case.)
Code: Select all
DefaultCategoryDataset.addValue("10", "XYZ", );
DefaultCategoryDataset.addValue("50", "XYZ", );
DefaultCategoryDataset.addValue("15", "ABC", );
This piece of code will render only two bars XYZ & ABC with the values 50 and 15 respectively.
Why is this happening and is it possible to render all 3 bars in the graph?
Thanks and regards,
Zulfikarali Barodawala
Zulfikarali Barodawala
-
paradoxoff
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Post
by paradoxoff » Thu Jun 11, 2009 2:17 pm
First of all, this code snippet will not compile.
A DefaultCategoryDataset uses an instance of DefaultKeyedValues2D for data strorage. if you add a value using an existing row and column key (e. g. a row/column key that is equal to an existing one), the old value will be overwritten.
To avoid that, you could write your own Comparable implementation that wraps another Comparable (such as a String) but returns false from its equals(Object o) method.