Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.0k views
in Technique[技术] by (71.8m points)

怎样设置echarts图标内部元素的宽高为自适应呢?

需求是做这个效果。图表占了宽度的60%因为想做成自适应。所以宽高不知道怎么设置才好?我自己随意调整了一下。效果并不满意。
在不知道图表所需要显示的数据个数的情况下,怎样做自适应呢?
我用的这个图表:
https://echarts.apache.org/ex...
如图:
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. echarts渲染绑定的元素外部回个父元素;
  2. 父元素根据弹性布局之类适应;
  3. echarts渲染绑定的元素直接设置width:100%;height:100%;
  4. 图表setOption后,直接resize一次,并且添加 window.addEventListener('resize')每次窗口变化时resize即可;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...