0

I want to customise my charts so I want to use a class customiser, I have used the following code to change the categorie label to vertical , but I don't know why it generate an error!

the code:

 public void customize(JFreeChart jfc, JRChart jrc) {
  CategoryPlot myPlot = jfc.getCategoryPlot();
  HorizontalCategoryAxis axis = (HorizontalCategoryAxis)myPlot.getDomainAxis();
  axis.setVerticalCategoryLabels(true);
 } 

the error is:

 cannot find symbol : Class HorizontalCategoryAxis

Also I have tried:

    CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer();
    CategoryItemLabelGenerator generator = new   StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.00"));
    renderer.setLabelGenerator(generator);
    renderer.setItemLabelsVisible(true);
    XYItemRenderer renderer2 = (XYItemRenderer) plot.getRenderer();
    XYItemLabelGenerator generator2 = new StandardXYItemLabelGenerator("{2}", new  DecimalFormat("0.00"));
    renderer.setLabelGenerator(generator);

and the errors:

cannot find symbol appear for the line :

renderer.setLabelGenerator(generator);

and

no suitable constructor for

XYItemLabelGenerator generator2 

my reference is:

http://files.blogjava.net/hao446tian/jfreechart-1.0.1-US_developer_guide.pdf

UPDATE Still I can't see the categorieExpression( on the Y axis) :(((

enter image description here

rym
  • 545
  • 6
  • 12
  • 36
  • The error is, it would seem, that `HorizontalCategoryAxis` is not in your class path. Ensure you have all the appropriate jars in your classpath. – Jes Aug 25 '11 at 15:13
  • possible duplicate of [What are the steps to use Cutomiser Chart Class?](http://stackoverflow.com/questions/7173261/what-are-the-steps-to-use-cutomiser-chart-class) – trashgod Aug 25 '11 at 15:43
  • @Jes ,I have add JfreChart.jar to my project, should I add somthing else? – rym Aug 26 '11 at 07:18
  • I believe the `HorizontalCategoryAxis` has been deprecateded, or at some point removed. What version of JFreeChart are you running? Your developer manual suggests you should be running 1.0.1. Check my answer for a possible solution. – Jes Aug 26 '11 at 08:39

1 Answers1

2

First of all your failed code seems to be version mismatch between your examples and the library you use. The setLabelGenerator method has been removed and replaced with setBaseItemLabelGenerator:

CategoryPlot plot = yourPlot;
CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer();
CategoryItemLabelGenerator generator = new   StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("0.00"));
renderer.setBaseItemLabelGenerator(generator);
renderer.setBaseItemLabelsVisible(true);
XYItemRenderer renderer2 = (XYItemRenderer) plot.getRenderer();
XYItemLabelGenerator generator2 = new StandardXYItemLabelGenerator("{2}", 
        new  DecimalFormat("0.00"),
        new  DecimalFormat("0.00"));
renderer.setBaseItemLabelGenerator(generator);

You can see in my example that the StandardXYItemLabelGenerator takes two formats, one for the x values and one for y.

As for the use of HorizontalCategoryAxis it suffered the same fate as setLabelGenerator. Assuming you want a vertical plot with a CategoryAxis that has labels that are vertical, not horizontal, you can use setLabelAngle to achieve the desired effect:

public void customize(JFreeChart jfc, JRChart jrc) {
    CategoryPlot myPlot = jfc.getCategoryPlot();
    CategoryAxis axis = myPlot.getDomainAxis();
    axis.setLabelAngle(-Math.PI / 2);
}
Jes
  • 2,748
  • 18
  • 22
  • ,I have tried your answer ,the error disappeared and a report was generated ,I will update my post with the report it still a mess! – rym Aug 26 '11 at 11:45
  • It seems the label angle is not being set. Are you certain the category axis is not set elsewhere? Try setting a breakpoint in the body of `setLabelAngle`. – Jes Aug 26 '11 at 12:26
  • hello, yes you are right :) ,final question could In use the same class custoiser for a barChart 3D ? – rym Aug 26 '11 at 13:17
  • The code so far is generic for the `BarRenderer` and `CategoryPlot` respectively. `BarRenderer3D` extends `BarRenderer` so you should be able to just switch the renderer out. – Jes Aug 26 '11 at 14:35
  • +1 for elucidating the evolving API, which is instructive in itself. – trashgod Sep 02 '11 at 16:03