echarts给柱状图添加文字
一、在echarts组件中的setOptions() 函数中添加labelOption对象
const _arry = []
const _series = []
const labelOption = {
show: true,
position: 'insideBottom',
distance: 15,
align: 'left',
verticalAlign: 'middle',
rotate: 90,
formatter: '{a}-{c}',
fontSize: 12,
rich: {
name: {}
}
}
二、在echartsLine.seriesData.forEach()中添加配置,给label添加以上对象样式
代码如下(示例):
echartsLine.seriesData.forEach(element => {
_arry.push(element.label)
_series.push({
name: element.label,
label: element.type === 'bar' ? labelOption : {},
smooth: true,
type: element.type === 'bar' ? 'bar' : 'line',
yAxisIndex: element.yAxisIndex,
data: element.data,
animationDuration: 2800,
animationEasing: 'cubicInOut'
})
})