开发者

Error with a class customiser for charts

开发者 https://www.devze.com 2023-03-30 21:57 出处:网络
I want to customise my charts so I want to use a class customiser, I have used the following codeto change the categorie label to vertical , but I don\'t know why it generate an error!

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 开发者_C百科:

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) :(((

Error with a class customiser for charts


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消