图表类定制器出错
我想自定义我的图表,所以我想使用类定制器, 我已使用以下代码将类别标签更改为 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) :(((
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您失败的代码似乎是您的示例和您使用的库之间的版本不匹配。
setLabelGenerator
方法已被删除并替换为setBaseItemLabelGenerator
:您可以在我的示例中看到
StandardXYItemLabelGenerator
采用两种格式,一种用于 x 值和 y 的一个。至于
HorizontalCategoryAxis
的使用,它遭遇了与setLabelGenerator
相同的命运。假设您想要一个带有垂直而不是水平标签的CategoryAxis
的垂直图,您可以使用setLabelAngle
来实现所需的效果: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 withsetBaseItemLabelGenerator
: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 assetLabelGenerator
. Assuming you want a vertical plot with aCategoryAxis
that has labels that are vertical, not horizontal, you can usesetLabelAngle
to achieve the desired effect: