O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exporting charts as images

PrimeFaces provides the ability to export charts generated by various chart components as images using the client-side API method widgetVar.exportAsImage().

<h:form id="form1">
  <p:lineChart widgetVar="chartWgt" 
    value="#{chartController.chartModel}" 
      style="width:500px;height:300px" 
      title="Linear Chart" 
      legendPosition="e"
      minY="0" maxY="600"/>
  
  <p:commandButton type="button" value="Export" 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>
<script type="text/javascript">
  function exportChart() 
  {
    $(PrimeFaces.escapeClientId('form1:output')).empty().append(chartWgt.exportAsImage() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required