如何在条形图上设置基准线? [英] How to put benchmark line on barchart?

查看:473
本文介绍了如何在条形图上设置基准线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用jfreechart与Jasper报告,我们正在努力将基准线放在条形图上。

We are using the jfreechart with Jasper reports and we are struggling to put the benchmark line on the bar chart.

如何使用jasper报告实现这一目标?

How can this be achieved using jasper reports?

推荐答案

要在jasper报告中自定义条形图,请创建一个自定义程序类(ChartCustomizer),扩展 JRChartCustomizer

To customize your bar chart in jasper report create a customizer class (ChartCustomizer) extending the JRChartCustomizer.

public void customize(JFreeChart chart, ChartComponent chartComponent)
{
  //get the ploy
  CategoryPlot plot = (CategoryPlot) chart.getPlot();

  //Now add your markers
  ValueMarker vm = new ValueMarker(200); //200 is the position you like it to be
  vm.setPaint(Color.RED);
  vm.setStroke(new BasicStroke(1));
  vm.setLabel("BeanchMark value"); //The label
  vm.setLabelAnchor(RectangleAnchor.TOP);
  vm.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
  plot.addRangeMarker(vm);
}

将类添加到classpath并在jrxml中设置 customizerClass attribute

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

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

这篇关于如何在条形图上设置基准线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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