Reputation: 2324
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!
Upvotes: 1
Views: 3538
Reputation: 133
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";
Upvotes: 4
Reputation: 2967
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);
});
Upvotes: 1