Im trying the Echarts library for my graphs. I'd like to resize the plots when the window's resize trigger is fired but I can't find the way to do it.
Thanx for your help
Definition and UsageThe onresize event occurs when the browser window has been resized. Tip: To get the size of an element, use the clientWidth, clientHeight, innerWidth, innerHeight, outerWidth, outerHeight, offsetWidth and/or offsetHeight properties.
The resize event fires when the document view (window) has been resized. This event is not cancelable and does not bubble. In some earlier browsers it was possible to register resize event handlers on any HTML element.
var plot = echarts.init(yourDom);
plot.setOption({...});
window.onresize = function() {
plot.resize();
};
var allCharts = $('.charts');
setTimeout(function(){
for(var i=0;i<allCharts.length;i++){
var $item = $(allCharts[i]);
echarts.getInstanceById($item.attr('_echarts_instance_')).resize();
}
},100) `
With jQuery:
// resize all charts
$(window).on('resize', function(){
$("[_echarts_instance_]").each(function(){
window.echarts.getInstanceById($(this).attr('_echarts_instance_')).resize()
});
});
window.onresize = function() {
$(".ga-charts").each(function(){
var id = $(this).attr('_echarts_instance_');
window.echarts.getInstanceById(id).resize();
});
};
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