Print multiple Primefaces Chart.js

Viewed 183

I want to print multiple p:pieChart that generate inside a p:repeat so I do not know how many charts there are.I just want to get a PDF with all the charts basically. I have tried using this:

<p:printer target="@([id$=divWhereAllTheChartsAre]) " />

But the charts appear blank. I also saw this in the official documentation:

<script type="text/javascript">
//<![CDATA[
    function exportChart() {
        //export image
        $('#output').empty().append(PF('chart').exportAsImage());

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

But I cannot get the component by its PF widgetVar because there are more than one. Is there any other way to export the charts?

I am working with the primefaces7.0.jar, thanks.

1 Answers

As suggested, I used a bean property to name each component using a counter. After this, I could just reference each one using a loop.

Bean:

private int widgetCounter= 0;
public String generateWidgetVar() {
    return "chart" + (this.widgetCorrelativo++);
}

XHTML:

<p:pieChart widgetVar="#{cargarReporteBean.generateWidgetVar()}"
Related