I am using HighCharts 4.0.4 and I have a chart with a custom legend in this way:
<div class="wrapper">
<div class="element">
<div id="chart"></div>
</div>
<div class="legend">
Legend
</div>
</div>
The CSS
looks like this. The wrapper
is a table, so that I can use in the legend with table-cell
a vertical-align: middle
. I want to have both 50% of the width of the wrapper
.
.wrapper {
display: table;
width: 100%;
}
.element {
display: table-cell;
width: 50%;
}
.legend {
display: table-cell;
width: 50%;
vertical-align: middle;
}
#chart {
width: 100%;
}
The problem is, I created a JSFiddle here, "running" the code if the output/result window is small, I see the 50%:50%. Resizing the output window and make it larger, everything is okay, the 50%:50% is okay, but making the output window smaller, the chart does not resize properly.
I saw some solutions with $(window).resize();
. In my case, I tried to use the outerHeight
, but the values only changes if I make the screen size bigger. So I found this solution which works:
$('#chart').highcharts().setSize(
$(".wrapper").width() / 2, $('#chart').highcharts().height, doAnimation = true
);
But is there also a solution which does not need to use JavaScript, only HTML and CSS?
This should be done with just CSS... no resizing functions.
try adding
position:absolute
to your chart css propertyThe new css for
#chart
would look like this:I think this is the effect you want.
Check my Fiddle
note: I removed all resizing Javascript
Follow Up:
If you need to resize Highcharts on window resize with animation, you can do it with this syntax.
I think this is more what you wanted using the Highchart
setSize
method with animation instead of CSS)Fiddle
Something like this? For me, use perfect.
CSS:
JS:
http://jsfiddle.net/L9gubqvy/9/