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
 |  Show 2 more ments

1 Answer 1

Reset to default 3

If 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