答案 0 :(得分:2)
要在jasper报告中自定义条形图,请创建一个扩展JRChartCustomizer的自定义程序类(ChartCustomizer)。
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
属性
<barChart>
<chart customizerClass="my.package.ChartCustomizer">
....
</chart>
...
</barChart>
答案 1 :(得分:0)
我们已在自定义类
中使用以下代码解决了这个问题ValueMarker marker = new ValueMarker(30);
marker.setLabel("Average 30%");
marker.setPaint(Color.black);
plot.addRangeMarker(marker);
但是我们需要更改标签位置,目前它显示在行的开头。
答案 2 :(得分:0)