答案 0 :(得分:4)
要在条形图上绘制一条线,请在CategoryPlot中添加ValueMarker。
在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-jasper setCustomizerClass
(如在jrxml中)
DJBarChartBuilder().setCustomizerClass("MyChartCustomizer");
结果示例
注意:在示例中没有使用包名称,如果包中有MyChartCustomizer
,则需要在setCustomizerClass
示例"my.package.MyChartCustomizer"
<中指明完整包名称/ p>
答案 1 :(得分:0)