首先,我必须告诉您,我不是以英语为母语的人,所以我希望我能正确地向您解释我的问题。
我在以 PDF 格式导出条形图时遇到了一些问题。我正在使用 PrimeFaces 3.5 和 Tomcat v7。
经过一番研究,我了解到,不能直接以 PDF 格式导出图表。但这似乎是一种将图表保存在 png 或 jpeg 等图像中的方法。
我发现了这个: http: //www.primefaces.org/showcase-labs/ui/chartExport.jsf但它只是一种打印屏幕的方式,我想保存它以便在我的 pdf 报告中使用它。
我也看到了 JFreeChart 解决方案,但我真的想在我的 html 页面和我的 PDF 报告中保留相同的图表。
这是我的代码:
<h:form id="finalreport">
<c:if test="#{treeBean.finalPrintReport.create == 1}">
<h1>
<h:outputText value="#{treeBean.finalPrintReport.namefinalreport}"
escape="false" />
</h1>
<p:dataTable id="dataTableReport" var="row"
value="#{treeBean.finalPrintReport.allData}" paginator="true"
rows="10">
<p:columns value="#{treeBean.finalPrintReport.column}" var="column"
columnIndexVar="colIndex">
<f:facet name="header">
<h:outputText value="#{column}" />
</f:facet>
<h:outputText value="#{row[colIndex]}" />
</p:columns>
</p:dataTable>
<br />
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="dataTableReport"
fileName="Report" preProcessor="#{treeBean.createPDF}" />
</h:commandLink>
</c:if>
</h:form>
<!-- Graph -->
<h:form id="graph">
<c:if test="#{treeBean.finalPrintReport.create == 1}">
<c:if test="#{treeBean.finalPrintReport.propertyOfFinalReport.graph == true}">
<p:barChart id="basic" value="#{treeBean.chartbar2d}"
legendPosition="ne" title="Basic Bar Chart"
style="height:300px" />
</c:if>
</c:if>
</h:form>
谢谢