2013-02-21 119 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