admin管理员组文章数量:1316523
Is it possible to create ECharts line chart without specifying it's container height - make it responsive to the actual data.
The number of items in Y axis can vary.
By default, when I don't define the height of the container, it will be 0 and the chart is not visible.
In this example there are 6 items (months) in Y axis, but what if I wanted to show 12 months in the same container, without making the bars 50% narrower?
Is it possible to create ECharts line chart without specifying it's container height - make it responsive to the actual data.
The number of items in Y axis can vary.
By default, when I don't define the height of the container, it will be 0 and the chart is not visible.
In this example there are 6 items (months) in Y axis, but what if I wanted to show 12 months in the same container, without making the bars 50% narrower?
Share Improve this question edited Nov 10, 2016 at 8:29 Silver Ringvee asked Nov 8, 2016 at 12:11 Silver RingveeSilver Ringvee 5,5456 gold badges32 silver badges48 bronze badges 7- How would it know the height? Every chart I've ever seen requires that you pass in dimensions. As your data changes, the size would have to change, that would be really ugly. – Ruan Mendes Commented Nov 8, 2016 at 13:18
- 1 The area before and after the actual chart is fixed and the chart area would be responsive to the number of rows, bars or whatever the data type? – Silver Ringvee Commented Nov 8, 2016 at 13:20
- I don't really get it, how could the size change when the dimensions are defined? How is this done in the other charts then? – Silver Ringvee Commented Nov 8, 2016 at 13:30
- 1 By the way, your solution seems really simple, does it bother you that much? I wouldn't think twice about using it. – Ruan Mendes Commented Nov 8, 2016 at 13:59
- 1 Yes, figured that after asking the question. Will continue using it for now. Thanks – Silver Ringvee Commented Nov 8, 2016 at 14:02
1 Answer
Reset to default 3If you know how many rows or bars you are going to have, you can use it to calculate the height of the container.
For example, if each row is 31px and fixed height of graph header & footer is 200px you could use:
var chartHeight = dataValues.length * 31 + 200;
$('#graph-container').css({'height': chartHeight});
本文标签: javascriptECharts automatic heightStack Overflow
版权声明:本文标题:javascript - ECharts automatic height - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999039a2410632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论