我使用的是Dynamicreports4.1.1,其图表基于Jfreechart。
有点像烛台图或堆积图或分层图。
代码:
public class StackedBarChartReportTest {
public StackedBarChartReportTest() {
build();
}
private void build() {
FontBuilder boldFont = stl.fontArialBold().setFontSize(12);
TextColumnBuilder<String> itemColumn = col.column("Item", "item", type.stringType());
TextColumnBuilder<BigDecimal> bestColumn = col.column("Best", "best", type.bigDecimalType());
TextColumnBuilder<BigDecimal> worstColumn = col.column("Worst", "worst", type.bigDecimalType());
try {
report()
.setTemplate(Templates.reportTemplate)
.columns(itemColumn, bestColumn, worstColumn)
.title(Templates.createTitleComponent("StackedBarChart"))
.summary(
cht.stackedBarChart()
.customizers(new ChartCustomizer())
.setTitle("Stacked bar chart")
.setTitleFont(boldFont)
.setCategory(itemColumn)
.setShowValues(true)
.series(
cht.serie(bestColumn), cht.serie(worstColumn))
.setCategoryAxisFormat(
cht.axisFormat().setLabel("Item")))
.pageFooter(Templates.footerComponent)
.setDataSource(createDataSource())
.show();
} catch (DRException e) {
e.printStackTrace();
}
}
private class ChartCustomizer implements DRIChartCustomizer, Serializable {
private static final long serialVersionUID = 1L;
@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
// here customize,but have no idea...
}
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("item", "best", "worst");
dataSource.add("1Y", new BigDecimal(-10), new BigDecimal(-14.5));
dataSource.add("2Y", new BigDecimal(10), new BigDecimal(4));
dataSource.add("3Y", new BigDecimal(12), new BigDecimal(-2));
return dataSource;
}
public static void main(String[] args) {
new StackedBarChartReportTest();
}
不知道如何开始或是否有这样的图表?