BarChart条形值标签被边距隐藏 [英] BarChart bar value labels are hidden by the margin

查看:157
本文介绍了BarChart条形值标签被边距隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jaspersoft Studio创建带有图表的报告文件。



当我使用条形图并尝试显示条形图标签时,这些标签由利润率。在我看来,这看起来像一个错误,有没有办法正确显示标签?



为了更好地说明问题,你可以在图片上看到问题并找到红色的预期值。





我尝试使用巨大的边距值没有任何视觉效果。

  rangeAxis.setUpperMargin(200); 
rangeAxis.setLowerMargin(200);

我也玩过边界。在这种情况下,我可以看到整个标签,但问题是值不会停在100(这不是一个有效的解决方案)。



我发现了边际被完全忽略的原因:


public void setUpperMargin(double margin)
设置轴的上边距(如轴范围的百分比)并将AxisChangeEvent发送给所有已注册的侦听器。 仅在自动计算轴范围时添加此边距 - 如果手动设置轴范围,则忽略边距。


但是如果我删除了边距,那么边界将从0-125自动计算到什么不是范围。



像往常一样,任何建议都是欢迎。



为了更好地理解,您可以从我的GitHub存储库下载示例代码。



GitHub:< a href =https://github.com/MichaelKnight/jaspertest.git =nofollow noreferrer> https://github.com/MichaelKnight/jaspertest.git

解决方案

jasper报告中的图表由 jfreechart 库。在您的情况下,您可以:



1)设置范围轴上边距以给予值标签更多空间(请参阅jfreechart BarChartDemo5)。



2)在条形图内绘制标签(参见jfreechart BarChartDemo7)编辑后如果需要固定轴的上限值,则需要使用此标签,因此标签如果上限等于最大条形值,则没有剩余空间



要在jasper报告中自定义条形图,请创建一个扩展 JRChartCustomizer 。这将公开:

  public void customize(JFreeChart chart,ChartComponent chartComponent)
{
// Simple在范围轴上增加上边距的示例,在条形图内打印标签
//请参阅jfreechart BarChartDemo7
CategoryPlot plot =(CategoryPlot)chart.getPlot();
NumberAxis rangeAxis =(NumberAxis)plot.getRangeAxis();
rangeAxis.setUpperMargin(0.20); //增加或减少以百分比形式更改上边距(0 - > 1.0)
rangeAxis.setAutoRange(true); //确保没有设置固定范围
}

将类添加到classpath和在jrxml中设置 customizerClass 属性

  < BARCHART> 
< chart customizerClass =my.package.MyChartCustomizer>
....
< / chart>
...
< / barChart>


I am using Jaspersoft Studio to create the report file with charts.

When I use the bar chart and try to display the bar values labels these are covered by the margins. In my opinion this looks like a bug, is there any way to show the labels properly?

To better illustrate the problem you can see the issue on the picture and also find in red the expected values.

EDIT

Here is my progress customizing the bar chat. So far I could make several changes but I am stuck with the most important one.

I tried using huge values for the margins without any visual effect.

    rangeAxis.setUpperMargin(200);
    rangeAxis.setLowerMargin(200);

I also played with the bounds. In that case I can see the entire labels but the problem is that the values won't stop at 100 (so that is not a valid solution).

I discovered the reason why the margins are completely ignored:

public void setUpperMargin(double margin) Sets the upper margin for the axis (as a percentage of the axis range) and sends an AxisChangeEvent to all registered listeners. This margin is added only when the axis range is auto-calculated - if you set the axis range manually, the margin is ignored.

But if I remove the margins then the bounds are autocalculated from 0-125 what is not the scope.

As usual, any suggestion will be welcome.

For a better understanding you can download the sample code from my GitHub repository.

GitHub: https://github.com/MichaelKnight/jaspertest.git

解决方案

The chart in jasper report is generated by the library. In your case you can:

1) Set the range axis upper margin to give more space to value label (see jfreechart BarChartDemo5).

2) Draw the label inside the bar (see jfreechart BarChartDemo7) After edit if you need fixed upper value of axis you need to use this, hence the label has no space left if upper limit equals max bar value

To customize your bar chart in jasper report create a customizer class (MyChartCustomizer) extending the JRChartCustomizer. This will expose:

public void customize(JFreeChart chart, ChartComponent chartComponent)
{
  //Simple example of increasing upper margin on range axis, to print label
  //inside of bar see jfreechart BarChartDemo7
  CategoryPlot plot = (CategoryPlot) chart.getPlot();
  NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
  rangeAxis.setUpperMargin(0.20); //Increase or decrease to change upper margin in percentages (0 --> 1.0)
  rangeAxis.setAutoRange(true); //make sure that fixed range is not set
}

add the class to classpath and in jrxml set the customizerClass attribute

<barChart>
    <chart customizerClass="my.package.MyChartCustomizer">
   ....
    </chart>
   ...
</barChart>

这篇关于BarChart条形值标签被边距隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆