echarts柱状图如何把legend的位置放在柱状图下方
时间: 2023-07-22 11:37:55 浏览: 177
要将 Echarts 的柱状图中的 legend 放在下方,可以设置 legend 的 `bottom` 属性。具体实现步骤如下:
1. 设置 `legend` 的 `bottom` 属性为 `0`,表示将 legend 放在底部。
```
option = {
...
legend: {
bottom: 0,
...
},
...
};
```
2. 如果柱状图的高度比较小,可能会导致 legend 覆盖柱状图,此时可以通过设置 `grid` 的 `bottom` 属性来调整柱状图的位置。
```
option = {
...
grid: {
bottom: 60, // 调整柱状图的位置,留出足够空间放置 legend
...
},
...
legend: {
bottom: 0 // 将 legend 放在底部
}
};
// 初始化柱状图
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption(option);
```
完整代码示例:
```
option = {
xAxis: {
data: ['A', 'B', 'C', 'D', 'E']
},
yAxis: {},
series: [{
type: 'bar',
data: [5, 20, 36, 10, 10]
}],
grid: {
bottom: 60 // 调整柱状图的位置,留出足够空间放置 legend
},
legend: {
bottom: 0 // 将 legend 放在底部
}
};
// 初始化柱状图
var myChart = echarts.init(document.getElementById('main'));
myChart.setOption(option);
```
以上代码实现了将 Echarts 的柱状图中的 legend 放在下方。
阅读全文
相关推荐


















