0

How can I make use of downloadAsImage() to download/print the chart in PNG format?

I used exportToChart() as mentioned below but it just displays the chart under the existing chart.

<h:form id="exportForm">
    <h:commandButton id="exportButton" value="Export as Image"
                     onclick="exportChart.exportToImage(ice.ace.jq('.chartExport')); 
                              return false;" />
<ace:chart ...
               widgetVar="exportChart" />
</h:form>
<h:graphicImage styleClass="chartExport" />  

Edit
Tried this:

<ice:commandButton  value="Print" 
        onclick="$('barChart').printElement();" >
        <ace:printer for="barChart"></ace:printer>
</ice:commandButton>  

where barChart is id for the chart. This only prints the legend and numeric values but not actual graph.

intruder
  • 417
  • 1
  • 3
  • 18
  • By 'printing' it... via a print button... Or check if IceFaces has a 'print' component (PrimeFaces has) – Kukeltje Jun 13 '18 at 17:05
  • I don't wanna use a print button or just do "Cntrl+P". I want a dedicated button to export/download/print the chart. And yes, I tried with but it just prints numerics, not the whole image. – intruder Jun 13 '18 at 17:23
  • If you exported the image first I'd expect `ace:printer` to print the image as well. And you cannot directly print from a webpage without having the print window popping up. Tried `window.print()` in the onlclick after the export (or whatever the javascript function for 'print' is.... – Kukeltje Jun 13 '18 at 17:26
  • I'm unable to export it. When I use exportToImage(), it displays the image right under the graph/chart with same dimensions. And yes, I do agree about the print window popping up. I just want to print a particular chart from a page with 2-3 charts/graphs. (separate print button for each chart/graph) – intruder Jun 13 '18 at 17:29
  • Well, that is displays it right below the original chart is because that is what your (x)html does... Try using the solution in the 12 upvoted answer in https://stackoverflow.com/questions/6500962/how-to-print-only-a-selected-html-element – Kukeltje Jun 13 '18 at 17:42
  • In PrimeFaces (on which these ace components are based) I can print the **exported** image with the `p:printer` (targetting the id of the image tag where the exported image is ending up on. I can also use the javascript that is on the button of the printer after the export in the same javascript. So the same might work for icefaces – Kukeltje Jun 13 '18 at 18:13
  • I've added what I've tried in the question. – intruder Jun 13 '18 at 18:26
  • Shouldn't `onclick="$('barChart').printElement();"` be an export? Now you twice print it. – Kukeltje Jun 13 '18 at 18:30
  • I meant to say I used this: onclick="exportChart.exportToImage(ice.ace.jq('.chartExport'));" and this: " onclick="$('barChart').printElement();" on two different buttons to see which one works. First one just displays image under the chart and second one prints legend and numeric but not the whole graph. – intruder Jun 13 '18 at 18:33
  • Combine Them.... – Kukeltje Jun 13 '18 at 19:32

0 Answers0