In the BarChartDemo3.java file, I wanted to know how to have multiple bars with different colors, all in the same series. Or, if that's not possible, to have lables for each category at the bottom.
Here's what I DID figure out how to do:
Have the lables at the bottom, but with all the bars the same color.
-or-
Have the bars all different colors, but with one lable encompassing all series (one lable of the category that they all belong to).
<---------------------------------------------------
This is just for a reference. I figured out what was wrong since then.
(it was my mistake)
Take a look at BarChartDemo3.java - it uses a "custom renderer" to display a single series with different colors for each bar:
Code: Select all
CategoryItemRenderer renderer = new CustomRenderer(
new Paint[] {Color.red, Color.blue, Color.green,
Color.yellow, Color.orange, Color.cyan,
Color.magenta, Color.blue}
);
Great, I thought. I'll use one of them there "custom renderers". I come to find out, though, that the code in the example doesn't work because I'm using version 1.0.1. A search through the pdf reveals nothing about "CustomRenderer", and a grep through the source code reveals the same thing. Ok, I guess that function is old and the auther isn't concerned enough about backward compatibility to keep the same functionality.
----------------------------------------------------------------->
In the pdf, there is a section on the CategorySeriesLabelGenerator, which I assume is what GENERATES the LABELS for a SERIES in a CATEGORYdataset-based chart. Correct me if I'm wrong, I didn't see any simple drawing of a bar graph with lines pointing to different parts of the chart, explaining what class represents what part and so forth. (That would have saved a lot of time, though). Here's some example code in the pdf:
Code: Select all
CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryItemRenderer renderer = plot.getRenderer();
CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator(
"{2}", new DecimalFormat("0.00"));
renderer.setLabelGenerator(generator);
renderer.setItemLabelsVisible(true);
1) there IS NO Constructor Method --
StandardCategorySeriesLabelGenerator(String, DecimalFormat);
..., not with that signature, anyway.
( There IS, however, a constructor of StandardCategoryItemLabelGenerator with this signature.
2) There IS NO method --
setLabelGenerator(generator);
...in the class, or in any class in the heirarchy of CategoryItemRenderer, although this method DOES exist for Pie charts and Spider charts. NOT IN THE RENDERER, mind you, but in the plot class.
I'm starting to ask myself: Is this old 0.x code that the auther just cut-and pasted into the 1.0.1 documentation?
I don't know. I've only been playing around with JFreeChart for a couple of days, so I don't really know a whole lot about it.
Anyway, PLEASE, if anyone has an answer to this, let me know. And should I just revert to the 0.x version? I have a fealing that I'l be running into the same problem, with some code not working with the old library because everything is mixed up.
I'm all about open source, but... we really have to have some better documentation. How about a wiki?