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?
To redraw the chart you can simply use redraw() method (https://api.highcharts.com/class-refere ... art#redraw). You might also want to check update() method (https://api.highcharts.com/class-refere ... art#update).
Highcharts - Updating a chart's option after initial render.
use chart. setSize(width, height, doAnimation = true); in your actual resize function to set the height and width dynamically.
destroy () - Removes the chart and purges memory. This method should be called before writing a new chart into the same container. It is called internally on window unload to prevent leaks. var hc_options = { chart: { renderTo: 'container' }, series: [{ name: 'USD to EUR', data: usdeur }] }; var chart=new Highcharts.
Did 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]
}]
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With