on my webpage is a chart drawn with Highchart. Now, if i resize my whole window i want this chart to adjusts its size (especially the width). The Code looks similar to this:
window.onresize=function(){resized();}
function resized()
{
$("#container").highcharts().redraw();
}
If I overwrite the redraw event (with something like "alert("resized");") I will get a result so the method should be called - but the chart doesn't changes its size. I also tried to set the charts size manually with
$("#container").highcharts().setSize(width, height, false);
But both ways didn't work. Is there any other solution?
on my webpage is a chart drawn with Highchart. Now, if i resize my whole window i want this chart to adjusts its size (especially the width). The Code looks similar to this:
window.onresize=function(){resized();}
function resized()
{
$("#container").highcharts().redraw();
}
If I overwrite the redraw event (with something like "alert("resized");") I will get a result so the method should be called - but the chart doesn't changes its size. I also tried to set the charts size manually with
$("#container").highcharts().setSize(width, height, false);
But both ways didn't work. Is there any other solution?
Share Improve this question asked Apr 15, 2014 at 11:27 PhilippPhilipp 8071 gold badge10 silver badges22 bronze badges 7- 2 Why did you set redraw=false in setSize? If you won't redraw chart after setSize then you won't see effect.. Anyway, jsFiddle demo would be great. In general, it should just work. – Paweł Fus Commented Apr 15, 2014 at 13:30
- 1 Well, yeah.. this solved my problem.. really embarassing :) Thanks – Philipp Commented Apr 15, 2014 at 13:54
- After reading api.highcharts./highcharts#Chart.setSize it's not important* if the 3rd parameter is true or false. *(just for perfomance reasons) – Philipp Commented Apr 15, 2014 at 14:01
- Well, if you will create demo with that issue, I will check this out :) – Paweł Fus Commented Apr 15, 2014 at 14:03
- @PawełFus: jsfiddle/LLExL/2632 – Philipp Commented Apr 15, 2014 at 14:39
1 Answer
Reset to default 2Did you try code in this manner so it will automatically handle chart resizing on window resize.
// create the chart
var chart = Highcharts.chart('container', {
chart: {
events: {
redraw: function () {
var label = this.renderer.label('The chart was just redrawn', 100, 120)
.attr({
fill: Highcharts.getOptions().colors[0],
padding: 10,
r: 5,
zIndex: 8
})
.css({
color: '#FFFFFF'
})
.add();
setTimeout(function () {
label.fadeOut();
}, 1000);
}
}
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});