echarts图表的自适应处理,包含同页面单个图表和多个图表两种情况

一:同页面单个图表的自适应处理

  // 基于准备好的dom,初始化echarts实例
  var chinaMap = echarts.init(document.getElementById("china-map"));
  window.onresize = chinaMap.resize; // 窗口或框架被调整大小时执行chinaMap.resize

这是单个图表的情况,要是多个图表,就会发现这样的写法会不起作用。

二:同页面多个图表的自适应处理

  // 基于准备好的dom,初始化echarts实例
  var myChart = echarts.init(document.getElementById("first"));
  var secondChart = echarts.init(document.getElementById("second"));
  var thirdChart = echarts.init(document.getElementById("third"));
  var fourthChart = echarts.init(document.getElementById("fourth"));
  window.addEventListener("resize", () => {
    
    
    myChart.resize();
    secondChart.resize();
    thirdChart.resize();
    fourthChart.resize();
  });

参考

猜你喜欢

转载自blog.csdn.net/weixin_45844049/article/details/109507977
今日推荐