我试图设计一个带有条形图的报表,其中我需要添加一个阈值。我试过用多轴图,不同轴的比例尺总是不同的.
有没有其他的解决方案来添加线到条形图?
我的预期输出如下所示:
发布于 2016-02-06 07:39:25
要在条形图上画一条线,需要向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>
如果您使用的是动态报告,您可以直接在代码中添加它
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);
}
});
如果您正在使用动态贾斯珀 setCustomizerClass
(如jrxml中的)
DJBarChartBuilder().setCustomizerClass("MyChartCustomizer");
结果示例
注意:在示例中不使用包名,如果MyChartCustomizer
位于包的完整包名中,则需要在setCustomizerClass
示例"my.package.MyChartCustomizer"
中指示
发布于 2021-07-02 01:52:00
对于一条水平线,可以使用提供的图表自定义程序:
转到图表->属性->图表(选项卡) ->图表自定义器
在那里,您可以添加一个范围间隔标记,并使用所需的值(在您的示例中为13000)使用开始值和结束值配置它。
这样,您就可以在13000的垂直值中绘制一条水平线。
https://stackoverflow.com/questions/35228941
复制相似问题