[英]Generating PDF report : jFreeChart and DynamicReports
我需要生成一个报告,如下所示:
我设计了一个在NetBeans中使用swing来输入详细信息的GUI:
我使用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
);
输出:
我在互联网上搜索并阅读到可以使用iText或JasperReports或DynamicReports(基于Jasper Report)
http://www.dynamicreports.org/getting_started.html#step9
我发现使用动态报告更加容易。 我的问题是-我是否可以将DynamicReports用于我的目的(我想-是的,请看示例报告),如果是,那么如何将jFreeChart导出到该报告中。
请帮助,因为我没有太多时间来完成这个项目。
谢谢
您可以直接在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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.