本文介绍了PrimeFaces打印不适用于p:chart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正像下面那样使用素面打印
I'm using primeface print just like below
<ui:define name="content" id="content">
<h:form id="common_chart_form" prependId="flase">
<p:growl id="growl" showDetail="true" autoUpdate="true"
sticky="false" />
<p:outputLabel id="labelvalue" value="aaaaaaaaaa"/>
<p:chart id="chart" type="bar"
model="#{commonChartController.barModel}" style="height:300px" />
<p:commandButton value="Print" type="button" icon="ui-icon-print">
<p:printer target="chart" />
</p:commandButton>
<p:commandButton value="Back" action="admin_sales_reports" />
</h:form>
</ui:define>
我需要打印图表,但不幸的是它无法打印.然后要测试打印目标,我试图打印"labelvalue",它打印了我在此代码中做的错误的事情
i need to print the chart but unfortunately it cannot print. then to test the print target i tried to print the "labelvalue" it printed what is the wrong thing that im doing in this code
这是页面的屏幕截图
推荐答案
您可以用一种更加优雅的方式来实现它,而无需在页面中声明outputPanel:
You can do it in a more elegant way, without the need of the outputPanel declared in the page:
-
JavaScript函数:
Javascript function:
function print(component){
var out = document.createElement('div');
out.appendChild(PF(component).exportAsImage());
var innerHTML = out.innerHTML;
var openWindow = window.open('', 'Report', '');
openWindow.document.write(innerHTML);
openWindow.document.close();
openWindow.focus();
openWindow.print();
openWindow.close();
}
为图表定义widgetVar:
Define widgetVar for chart:
<p:chart widgetVar="chart2" type="bar" model="#{chartsBean.barModel2}" />
调用打印功能:
Call the print function:
<p:commandLink id="lnk" onclick="print('chart2')"/>
这篇关于PrimeFaces打印不适用于p:chart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!