2013-06-28 32 views
0

我無法將素數面圖導出爲圖像。。不能在Primefaces中將圖表導出爲圖像?

categoryModel是一樣的總理出現在酒店。

它需要依賴lib來導出嗎?

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    ...... 
    template="/common/commonLayout.xhtml"> 
    <ui:define name="content"> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <script type="text/javascript"> 
      //<![CDATA[ 
      function exportChart() { 
       //export image 
       $('#output').empty().append(chart.exportAsImage()); 

       //show the dialog 
       dlg.show(); 
      } 
      //]]> 
     </script> 

     <h:form enctype="multipart/form-data"> 
      <p:barChart id="basic" value="#{ChartActionBean.categoryModel}" legendPosition="ne" 
         title="Bar Chart" widgetVar="chart" animate="true" yaxisLabel="Number of Count"/> 
      <p:commandButton type="button" value="Export" icon="ui-icon-extlink" onclick="exportChart()"/> 

      <p:dialog widgetVar="dlg" showEffect="fade" modal="true" header="Chart as an Image"> 
       <p:outputPanel id="output" layout="block" style="width:500px;height:300px"/> 
      </p:dialog> 
     </h:form> 
    </ui:define> 
</ui:composition> 

回答

2

在Showcase和Export按鈕和OutputPanel不包含在$('#output')中可以選擇預期的元素來追加圖像。

但在你的情況,你已經包裹在這樣JSF這些成分會產生像j_idt10和組件的id「輸出」形式的I​​D將成爲「j_idt10:輸出」。

要解決這個問題:

<h:form id="form1"> 
    //chart 
    // export button 
    //dialog containing outputPanel 
</h:form> 

而且在javascript:。

function exportChart() { 
    $('#form1\\:output').empty().append(chart.exportAsImage()); 
    dlg.show(); 
} 

或者乾脆把和$( '#輸出')外空的()追加(chart.exportAsImage ());將按預期工作。

0

我也認爲要指定模型,請使用模型屬性,而不是。所以你的情況這將是:

<p:barChart id="basic" model="#{ChartActionBean.categoryModel}" legendPosition="ne" title="Bar Chart" widgetVar="chart" animate="true" yaxisLabel="Number of Count"/>