0

我正在尝试使用JasperReportsDynamicJasper APIs动态生成报告。
我将饼图添加到报告中,但在 drb.addChart(djChart) 聊天添加为空之后。这是我的代码:

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;
}

请帮忙!

4

2 回答 2

0

我的问题是在设置查询之前构建报告。谢谢

于 2013-10-26T10:29:09.493 回答
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);
于 2016-02-01T22:01:35.250 回答