developer guide and code example issues

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
socrateone
Posts: 13
Joined: Fri Apr 28, 2006 2:53 pm

developer guide and code example issues

Post by socrateone » Tue May 02, 2006 7:38 pm

I just spent the $40 for the developer guide and the source code for the example in the demo app, thinking that it would be up to date. Specifically, I wanted to look at the source code for the examples.

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);
That would be great if there weren't a couple of problems with this code:
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?
Last edited by socrateone on Tue May 02, 2006 8:53 pm, edited 3 times in total.

socrateone
Posts: 13
Joined: Fri Apr 28, 2006 2:53 pm

Ok, so I'm an idiot...

Post by socrateone » Tue May 02, 2006 7:52 pm

I didn't realize that (duh) CUSTOMrendere was a CUSTOM class, ie: not in the JFreeChart library, but a CUSTOM-made inner class. Sorry, I'm not used to inner classes.

However, the problem with the Documentation still stands, I believe.

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

Re: developer guide and code example issues

Post by david.gilbert » Wed May 03, 2006 6:00 am

socrateone wrote: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).
One or two other people have requested the same thing, and I think it is a great idea. I'll try to get this done soon.
socrateone wrote: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);
That would be great if there weren't a couple of problems with this code:
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?
Yes, this is wrong - I will fix this today. Thanks for the feedback, it helps a lot to improve the quality of the documentation.
socrateone wrote:And should I just revert to the 0.x version?
No, definitely stick with the 1.0.x series. Now that the API is frozen, the documentation is getting easier to work on and improve. I'm aiming to release JFreeChart 1.0.2 this month, along with an update to the JFreeChart Developer Guide which you can download (all purchasers can download updates for at least 1 year from the date of purchase).

Once again, thanks for your feedback. Please let me know of any other problems you spot, I really do want to fix them (and I am actively reviewing the guide to find "bugs" myself).
David Gilbert
JFreeChart Project Leader

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

socrateone
Posts: 13
Joined: Fri Apr 28, 2006 2:53 pm

Thanks

Post by socrateone » Wed May 03, 2006 3:18 pm

Thank you for the reply. I'm glad to help.

However, I still don't know how to reference the series lables in a CategoryDataset-based chart. This isn't doing it:

Code: Select all

JFreeChart chart = ChartFactory.createBarChart(
			null, null, null, myDataSet, PlotOrientation.VERTICAL, false, false,	false 	);

CategoryPlot plot = (CategoryPlot)chart.getPlot();

CategoryItemRenderer renderer = new CustomRenderer(
     // my own custom renderer, which works (the colors in the series change)
     );

CategoryAxis domainAxis = plot.getDomainAxis();

domainAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));

plot.setRenderer(renderer);

The problem with this code is the "domainAxis.setLabelFont()" method. The method is referencing the CategoryAxis of the plot, which is NOT what I'm trying to get at. I'm trying to change the series lables, but can't find where to reference their fonts. I can change the font for the series ITEM labels. I can change the font of the the CATEGORY labels, but I can't figure out how to change the font of the series labels themselves.

Now, this DOES work:

Code: Select all

domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
It causes the labels that I want to work with to be displayed in the 45 degree angle. However, it seams like there is no:

Code: Select all

domainAxis.setCategoryLabelFont(new Font("SansSerif", Font.PLAIN, 10));
...method, which is what I need.

Any idea?

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 May 03, 2006 4:38 pm

You can use setTickLabelFont(). I might create an alias for this (setCategoryLabelFont()).
David Gilbert
JFreeChart Project Leader

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

socrateone
Posts: 13
Joined: Fri Apr 28, 2006 2:53 pm

Post by socrateone » Wed May 03, 2006 5:22 pm

Thank you!

That worked beautifully.

Why not have a base class or an interface of "label", and have all of these elements contain one of these labels. Then, you could reference that label and make any changes you want to it. ei:

Code: Select all


CategoryAxis domainAxis = plot.getDomainAxis();
Label label = domainAxis.getLabel();
label.setFont(new Font("SansSerif", Font.PLAIN, 10)); 
label.setPosition(p);
label.setBorder(new Stroke());
label.setBackgroundPaint(Color.white);
label.setBackgroundImage(image);
// ...etc.

That way, the user doesn't have to remember all the different methods of changing a font or other aspect of a lable, which would vary based on it's type. You could, instead, have subclasses of the Label class that have different members. However, outside of thier unique members, the interface would be standard.

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 May 09, 2006 9:45 am

I think some people would like that and others wouldn't. But now that the API is frozen, it doesn't matter anyway - it can't be changed (at least not until JFreeChart 2).
David Gilbert
JFreeChart Project Leader

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

Locked