2013-02-21 116 views
2

我需要生成一個報告,如下圖所示:生成PDF報告:JFreeChart的和DynamicReports

enter image description here

我設計用在NetBeans擺動進入細節的GUI:

enter image description here

使用jFreeChart生成的情節:

JFreeChart chart = ChartFactory.createXYLineChart(
"Hysteresis Plot", // chart title 
"Pounds(lb)", // domain axis label 
"Movement(inch)", // range axis label 
dataset, // data 
PlotOrientation.VERTICAL, // orientation 
false, // include legend 
true, // tooltips 
false // urls 
); 

輸出:

enter image description here

我正在尋找互聯網和讀取,我可以使用iText的或JasperReports的或DynamicReports(基於碧玉報告)

http://www.dynamicreports.org/getting_started.html#step9

我發現使用動態報表更。我的問題是 - 我可以使用DynamicReports用於我的目的(我想 - 是的,查看示例報告),如果是,那麼如何將jFreeChart導出到報告。

請幫忙,因爲我沒有太多時間完成這個項目。

感謝

回答

1

您可以DynamicReports,而不是直接的JFreeChart創建圖表。使用DynamicReports XYLineChartReport組件來執行此操作。請參閱示例代碼http://www.dynamicreports.org/examples/xylinechartreport.html

如果你想使用的JFreeChart輸出,圖表輸出到圖像,然後包括使用cmp.image()在報告中指出圖像:

// Create the chart. 
JFreeChart chart = ChartFactory.createXYLineChart(
    "Hysteresis Plot", // chart title 
    "Pounds(lb)", // domain axis label 
    "Movement(inch)", // range axis label 
    dataset, // data 
    PlotOrientation.VERTICAL, // orientation 
    false, // include legend 
    true, // tooltips 
    false // urls 
); 

// Export the chart to an image. 
BufferedImage image = chart.createBufferedImage(300, 300); 

report() 
    .title(cmp.text("XYZ HOSPITAL")) 
    .columns(fieldNameColumn, fieldValueColumn) 
    .summary(
     cmp.verticalList() 
      .add(cmp.text("HYSTERISIS PLOT")) 
      .add(cmp.text("A brief description of what this plot signifies")) 
      .add(cmp.image(image)) // Add the exported chart image to the report. 
      .add(cmp.text("REMARKS")) 
    ) 
    .setDataSource(createDataSource()) 
    .toPDF(outputStream); 
+0

我已經創建,如上面的圖所示的圖形用戶界面面板,現在我只需要將它導出到報告。 – 2013-02-21 12:28:49

+0

使用JFreeChart添加示例的編輯答案。 – 2013-02-21 14:28:38

+0

我搜索到了,我可以將jFreeChart保存爲.png或.jpeg圖像,然後將其包含在報告中,然後刪除圖像文件。所以基本上圖像文件作爲臨時文件。我想知道我是否可以直接導出爲iText呢? – 2013-02-22 05:31:30