我正在尝试使用 JasperReports 和 DynamicJasper API 动态生成报告。
我在报告中添加了饼图,但在drb.addChart(djChart)聊天后添加为null。这是我的代码:
private static DynamicReport createPieChart() {
DynamicReportBuilder drb = new DynamicReportBuilder();
DynamicReport dr = new DynamicReport();
try {
AbstractColumn columnName = ColumnBuilder.getNew().setColumnProperty("name", String.class.getName()).setTitle("Name").build();
AbstractColumn columnaId = ColumnBuilder.getNew().setColumnProperty("id", Integer.class.getName()).setTitle("Id").build();
AbstractColumn columnaTotal = ColumnBuilder.getNew().setColumnProperty("total", Long.class.getName()).setTitle("Total").build();
drb.addColumn(columnName);
drb.addColumn(columnaId);
drb.addColumn(columnaTotal);
DJChart djChart = new DJPieChartBuilder().setX(20)
.setY(10)
.setWidth(500)
.setHeight(250)
.setKey((PropertyColumn) columnaId)
.addSerie(columnaTotal).build();
drb.setUseFullPageWidth(true);
drb.addChart(djChart);
dr = drb.build();
} catch (Exception e) {
}
return dr;
}
请帮忙!
答案 0 :(得分:0)
我的问题是在设置查询之前构建报告。感谢
答案 1 :(得分:0)
请在此处找到示例代码
DJChart djChart = new DJLineChartBuilder()
//chart
.setX(20)
.setY(10)
.setWidth(500)
.setHeight(250)
.setCentered(false)
.setBackColor(Color.LIGHT_GRAY)
.setShowLegend(true)
.setPosition(DJChartOptions.POSITION_FOOTER)
.setTitle(new StringExpression() {
public Object evaluate(Map fields, Map variables, Map parameters) {
return variables.get("group_state_name");
}
})
.setTitleColor(Color.DARK_GRAY)
.setTitleFont(Font.ARIAL_BIG_BOLD)
.setSubtitle("subtitle")
.setSubtitleColor(Color.DARK_GRAY)
.setSubtitleFont(Font.COURIER_NEW_BIG_BOLD)
.setLegendColor(Color.DARK_GRAY)
.setLegendFont(Font.COURIER_NEW_MEDIUM_BOLD)
.setLegendBackgroundColor(Color.WHITE)
.setLegendPosition(DJChartOptions.EDGE_BOTTOM)
.setTitlePosition(DJChartOptions.EDGE_TOP)
.setLineStyle(DJChartOptions.LINE_STYLE_DOTTED)
.setLineWidth(1)
.setLineColor(Color.DARK_GRAY)
.setPadding(5)
//dataset
.setCategory((PropertyColumn) columnBranch)
.addSerie(columnaQuantity, "quant.")
.addSerie(columnAmount)
//plot
.setShowShapes(true)
.setShowLines(true)
.setCategoryAxisFormat(categoryAxisFormat)
.setValueAxisFormat(valueAxisFormat)
.build();
drb.addChart(djChart);
DJHyperLink djlink = new DJHyperLink();
djlink.setExpression(new StringExpression() {
public Object evaluate(Map fields, Map variables, Map parameters) {
return "http://thisIsAURL?count=" + variables.get("REPORT_COUNT");
}
});
djlink.setTooltip(new LiteralExpression("I'm a literal tootltip"));
djChart.setLink(djlink);