當一個echarts圖時,能夠這樣作html
//下面my_charts是html中echarts的ID
var myChart= echarts.init(document.getElementById("my_charts"));
myChart.setOption(option);
//假設實例的名字是myChart,在echats配置完實例之後,配置下面幾行代碼便可
window.onresize = function () {
myChart.resize();
}
若是頁面中有多個echart圖,並且在不一樣的js函數各自實例化,須要定義一個全局的對象,而後將各自的實例化id及echart實例對象裝進全局對象中,再統一自適應echarts
var chartJson;
func1(){
var myChart = echarts.init(document.getElementById('id1'));
...
myChart.setOption(option);
chartJson['id1'] = myChart;
}
func2(){
...
}
func3(){
...
}
//統一自適應
$(function(){
func1();
func2();
func3();
window.onresize = function() {
chartJson['id1'].resize();
chartJson['id2'].resize();
chartJson['id3'].resize();
};
})