打印不能与p:chart一起使用 [英] primeface print doesn't work with p:chart

查看:314
本文介绍了打印不能与p:chart一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im using primface print just like below

im 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:


  1. Javascript函数:

  1. 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')"/>
    


  • 这篇关于打印不能与p:chart一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆