echarts使用百度地图超出容器问题

百度地图会默认添加一个绝对定位的样式,但是绝对定位是相对于离他最近的position值为relative的容器的,因此只需要给容器添加position:relative属性值即可解决

<div id="echart5" echarts style="height: 100%; width: 100%;position: relative;"></div>

补充一个别的地图超出容器的问题:

1:页面初始化后或者刷新后发现超出容器,可以写一个延时器延时初始化图表,

  ngOnInit() {
    setTimeout(() => {
      this.setMap();
    }, 100);
  }

2:如果是屏幕改变后图表超出或者不能撑满,可以利用resize()方法
例如在angular中可以用:

import { HostListener } from '@angular/core';
@HostListener('window:resize', ['$event'])
(以下方法在窗口大小改变时自动执行)
  onResize(event) {
    if (this.chart && this.chart.hasOwnProperty('resize')) {
      this.chart.resize();
    }
    if (this.chart0 && this.chart0.hasOwnProperty('resize')) {
      this.chart0.resize();
    }
    if (this.chart2 && this.chart2.hasOwnProperty('resize')) {
      this.chart2.resize();
    }
  }

 

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值