图表类定制器出错

发布于 2024-12-01 21:11:07 字数 1541 浏览 2 评论 0原文

我想自定义我的图表,所以我想使用类定制器, 我已使用以下代码将类别标签更改为 Vertical ,但我不知道为什么它会生成错误!

代码:

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

错误是:

 cannot find symbol : Class HorizontalCategoryAxis

我也尝试过:

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

并且错误:

找不到符号出现在行:

renderer.setLabelGenerator(generator);

没有合适的构造函数

XYItemLabelGenerator generator2 

我参考是:

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

更新 我仍然看不到 Y 轴上的 categorieExpression() :(((

在此处输入图像描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十六岁半 2024-12-08 21:11:07

首先,您失败的代码似乎是您的示例和您使用的库之间的版本不匹配。 setLabelGenerator 方法已被删除并替换为 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);

您可以在我的示例中看到 StandardXYItemLabelGenerator 采用两种格式,一种用于 x 值和 y 的一个。

至于 Horizo​​ntalCategoryAxis 的使用,它遭遇了与 setLabelGenerator 相同的命运。假设您想要一个带有垂直而不是水平标签的 CategoryAxis 的垂直图,您可以使用 setLabelAngle 来实现所需的效果:

public void customize(JFreeChart jfc, JRChart jrc) {
    CategoryPlot myPlot = jfc.getCategoryPlot();
    CategoryAxis axis = myPlot.getDomainAxis();
    axis.setLabelAngle(-Math.PI / 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文