gpt4 book ai didi

java - 正在生成 PDF 报告 : jFreeChart and DynamicReports

转载 作者:行者123 更新时间:2023-11-30 11:35:39 26 4
gpt4 key购买 nike

我需要生成如下所示的报告:

enter image description here

我在 NetBeans 中使用 swing 设计了一个 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(基于 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);

关于java - 正在生成 PDF 报告 : jFreeChart and DynamicReports,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14996546/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com