简体   繁体   中英

Primefaces dynamic height of Bar Chart

I have a primefaces p:barChart component and I would like to set the style="height: #{backingBean.chartHeight}" dynamically according to the amount of data in the chart. The example here does not work so is there any other way to set the chart height dynamically? Thanks!

Another solution worked for me : instead of injecting height in the style, you can inject all the style option as a String. your code will look like this :

<p:barChart id="basic" value="#{backingBean.categoryModel}"
                    legendPosition="ne" title="Comparaison"
                    min="0" max="200"
                    style= "#{backingBean.chartStyle}" orientation="horizontal" />

And the height string in your backing bean :

private String chartStyle ="height:500px";

I guess you can do something like this

 <h:inputHidden value="#{backingBean.chartHeight}" id="chartheight"> // will be set if you set in the construtor.
  <p:barChart id="basicchart"  legendPosition="ne" /> 

and in JavaScript or Jquery on page load

 $(document).ready(function(){
      var val=$('#formId\\:chartheight').val();
      $('#formId\\:basicchart').css('height',val);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM