要在条形图上画一条线,请将ValueMarker 添加到 CategoryPlot。
在 jasper 报告中,我添加了一个 JRChartCustomizer
public class MyChartCustomizer implements JRChartCustomizer {
@Override
public void customize(JFreeChart jfchart, JRChart jrchart) {
CategoryPlot plot = (CategoryPlot) jfchart.getPlot();
//Set at what value you like the line, its color and size of stroke
ValueMarker vm = new ValueMarker(13000,Color.BLUE, new BasicStroke(2.0F));
//add marker to plot
plot.addRangeMarker(vm);
}
}
在 jrxml 中确保您的类在类路径中并在图表标签上设置 customizerClass 属性
<barChart>
<chart customizerClass="MyChartCustomizer">
....
</chart>
...
</barChart>
如果你使用dynamic-reports,可以直接在代码中添加
chart.addCustomizer(new DRIChartCustomizer() {
private static final long serialVersionUID = 1L;
@Override
public void customize(JFreeChart chart, ReportParameters arg1) {
CategoryPlot plot = (CategoryPlot) jfchart.getPlot();
ValueMarker vm = new ValueMarker(13000,Color.BLUE, new BasicStroke(2.0F));
plot.addRangeMarker(vm);
}
});
如果你使用dynamic-jaspersetCustomizerClass(如在jrxml中)
DJBarChartBuilder().setCustomizerClass("MyChartCustomizer");
结果示例
注意:示例中没有使用包名,如果MyChartCustomizer在包中,则需要在setCustomizerClass示例中注明完整的包名"my.package.MyChartCustomizer"