如果图例文字和图例垂直布局了但是不垂直居中,可以尝试设置图例的高度或者调整图例的位置。
1. 设置图例的高度
可以通过修改 `legend` 的 `itemHeight` 属性来设置图例的高度。如果将其设置为与扇形区域大小相同的值,则图例会与扇形区域垂直居中对齐。
例如:
```javascript
option = {
// ...
legend: {
orient: 'horizontal',
icon: 'circle',
top: 10,
left: 10,
x: 'left',
data: ['发送中', '发送成功', '发送失败'],
itemWidth: 8,
itemHeight: 40, // 设置图例高度为40
itemGap: 20,
textStyle: {
color: '#666666'
}
},
series: [
{
name: '邮件营销',
type: 'pie',
radius: ['40%', '60%'],
avoidLabelOverlap: false,
label: {
show: true,
position: 'outside',
formatter: '{b}: {c} ({d}%)'
},
emphasis: {
label: {
show: true,
fontSize: '30',
fontWeight: 'bold'
}
},
data: [
{value: 335, name: '发送中'},
{value: 310, name: '发送成功'},
{value: 234, name: '发送失败'}
]
}
]
};
```
2. 调整图例的位置
可以通过修改 `legend` 的 `top` 和 `left` 属性来调整图例的位置。根据扇形区域的大小和位置,适当调整图例的位置,使其与扇形区域垂直居中对齐。
例如:
```javascript
option = {
// ...
legend: {
orient: 'horizontal',
icon: 'circle',
top: 50, // 调整图例的位置
left: 10,