javascriptjsfchartsprimefacesjqplot

How to show or hide Primefaces chart Legend independently when you have two charts in the same view?


I have 2 charts in the same page. I'd like to show legends just in one chart, not both, but I have just a global solution. Thats my javascript code:

$.jqplot.preDrawHooks.push(function () {
this.legend.show = true;});

and my xhtml:

<p:chart id="chart17" responsive="true" type="bar"  model="#{chart17Bean.barModel}"  />
<p:chart id="chart18" responsive="true" type="bar"  model="#{chart18Bean.barModel}" />

Edited: I'm using Primefaces 6.1


Solution

  • Add this JS function on page

    function removeLegend() 
    {
         this.cfg.legend = {
              show: false
         };
    }
    

    and then in your managed bean add

    barModel.setExtender("removeLegend");
    

    where barModel is model of chart you want to have legend hidden.