Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ECharts: How to use the resize event of the window?

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

like image 523
Lolo Avatar asked Jan 06 '15 13:01

Lolo


People also ask

What is use of $( window resize ();?

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.

What is Resize event?

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.


4 Answers

var plot = echarts.init(yourDom);
plot.setOption({...});
window.onresize = function() {
  plot.resize();
};
like image 125
maralla Avatar answered Oct 23 '22 16:10

maralla


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) `
like image 26
TristaLee Avatar answered Oct 23 '22 15:10

TristaLee


With jQuery:

    // resize all charts
    $(window).on('resize', function(){
        $("[_echarts_instance_]").each(function(){
            window.echarts.getInstanceById($(this).attr('_echarts_instance_')).resize()
        });
    });
like image 22
Seyyed AMir Avatar answered Oct 23 '22 15:10

Seyyed AMir


        window.onresize = function() {
            $(".ga-charts").each(function(){
                var id = $(this).attr('_echarts_instance_');
                window.echarts.getInstanceById(id).resize();
            });
        };
like image 33
source box Avatar answered Oct 23 '22 15:10

source box