前言
基于echarts5.x和vue2实现
记录以便日后查阅
实现效果

代码实现
<template>
<div class="chart-wrap">
<div id="chart11" class="chart" />
</div>
</template>
<script>
export default {
name: 'Index',
data () {
return {
chart: null,
yData: [22, 6.3, 11.2, 3.2, 1.2],
xData: ['固定投资', '工业增加值', '规上工业产值', '规上利润', '规上税收']
}
},
mounted() {
this.createChartHandler()
},
methods: {
createChartHandler () {
this.chart = this.$echarts.init(document.getElementById('chart11'))
this.chart.setOption(this.getChartOption(this.yData, this.xData))
window.addEventListener('resize', () => {
setTimeout(() => {
this.chart.resize()
})
})
},
getChartOption (yData, xData) {
return {
tooltip: {
trigger: 'axis',
extraCssText: 'color:#fff;background: rgba(0, 38, 118, 0.5);border:none; box-shadow: 0px 0px 8px 1px rgba(0, 145, 255, 0.5);border-radius: 2px;',
axisPointer: {
type: 'none'
},
formatter: function (params) {
return params[0].name + ': ' + params[0].value + '亿'
}
},
grid: {
left: '5%',
right: '5%',
bottom: '0',
top: '10%',
containLabel: true
},
xAxis: {
data: xData,
axisTick: {
show: false
},
axisLine: {
lineStyle: {
color: 'rgba(42, 109, 251, 0.79)',
width: 1
}
},
axisLabel: {
interval: 0,
rotate: 0,
color: '#ffffff',
fontSize: 12
}
},
yAxis: {
axisTick: {
show: false
},
axisLine: {
show: true,
lineStyle: {
color: 'rgba(42, 109, 251, 0.79)',
width: 1
}
},
axisLabel: {
color: '#ffffff',
fontSize: 12
},
splitArea: {
lineStyle: 'dashed',
areaStyle: {
color: 'rgba(255,255,255,.5)'
}
},
splitLine: {
show: true,
lineStyle: {
color: 'rgba(0, 145, 255, 0.29)',
width: 1,
type: 'dashed'
}
}
},
color: ['rgba(6, 200, 140, 0.71)', 'rgba(2, 99, 255, 0.71)', 'rgba(255, 135, 23, 0.71)', 'rgba(252, 211, 31, 0.71)', 'rgba(17, 209, 247, 0.71)'],
series: [{
name: 'hill',
type: 'pictorialBar',
barCategoryGap: '0%',
symbolClip: true,
symbol: 'path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z',
itemStyle: {
color: function (params) {
var colorList = ['rgba(6, 200, 140, 0.71)', 'rgba(2, 99, 255, 0.71)', 'rgba(255, 135, 23, 0.71)', 'rgba(252, 211, 31, 0.71)', 'rgba(17, 209, 247, 0.71)']
return colorList[params.dataIndex]
}
},
label: {
show: true,
position: 'top',
color: 'inherit',
formatter: '{c}',
fontSize: 14
},
emphasis: {
itemStyle: {
opacity: 1
}
},
data: yData,
z: 10
}]
}
}
}
}
</script>