Reputation: 5419
For some reason my jqplot
(from a plugin) has a fixed height. This question is directly for people who use this plugin. Do you know how to make the height dynamically change depending on that of its parent? Like via just a 100% height?
Upvotes: 4
Views: 8082
Reputation: 1
Use the below steps; I think it's useful to draw a dynamic height graph
var minHeight=100;
if (30 * label.length > minHeight){
minHeight = 30 * label.length;
}
$('#chart1').height(minHeight);
Upvotes: 0
Reputation: 1451
I think the best way to do this is to determine the height of the parent container before initialising a chart. Container must also be stretched to fill the space reserved for a chart using CSS techniques. You can do it like this:
HTML:
<div class="container"><div id="chart"></div></div>
jQuery code:
var containerHeight = $("#chart").parent("div.container").height();
var chart = $.jqplot('chart', [data], {
height: containerHeight,
...
});
Of course, this approach wouldn't be suitable for all the situations out there.
Upvotes: 3
Reputation: 112
This is what I do. Change .96 to 1 and you should be able to achieve what you want.
$('#ChartID').height($('#ParentElement').height() * 0.96);
$('#ChartID').width($('#ParentElement').width() * 0.96);
I call these after the chart has been drawn.
Upvotes: 3