2013-10-24 109 views
0

我正在嘗試使用JasperReportsDynamicJasper API動態生成報告。
我在報告中添加了餅圖,但在drb.addChart(djChart)聊天添加爲空後。這裏是我的代碼:使用DynamicJasper API創建餅圖

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

請在這裏找到示例代碼

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