完整代码
<template>
<ve-histogram ref="chart_histogram"
height="380px"
style="margin-top:50px"
:width='chartWidth'
:data="chartData"
:settings="setting"
:events="chartSEvents"
:extend="extend" />
</template>
<script>
export default {
data() {
const that = this
this.setting = {
labelMap: {
'name': 'x轴名字',
'amount': '金额(万元)',
},
top: 50
},
this.extend = {
legend: {
show: false,
bottom: '10'
},
tooltip: {
position: [10, 320]
},
series: {
itemStyle: {
normal: {
color: function(params) {
var colorList = [];
if(params.name===that.selectName){
colorList[params.dataIndex] = "#CA41CA"
}else{
colorList[params.dataIndex] = "#cc99cc"
}
return colorList[params.dataIndex];
}
}
}
},
xAxis: {
axisLabel: {
interval: 0,
formatter: (v) => {
let txtArry = v.split('');
let rs = "";
for (var i = 0; i < txtArry.length; i++) {
rs += txtArry[i] + "\n";
}
return rs
},
textStyle: {
color: "#666666",
fontSize: 14,
}
},
},
yAxis: {
type: 'value',
name: '金额(万元)',
position: 'left',
color: "#666666",
fontSize: 14,
axisLine: {
show: true,
lineStyle: {
color: '#666666'
}
},
axisLabel: {
color: "#666666",
fontSize: 14,
formatter: '{value}'
}
}
}
this.chartSEvents = {
click: function (params) {
setTimeout(() => {
that.drawRing()
}, 100)
that.selectName = params.name
}
}
return {
selectName: '',
chartWidth: 'auto',
chartData:[
{
amount: 80,
name: "名字1"
},{
amount: 100,
name: "名字2"
},{
amount: 10,
name: "名字3"
},{
amount: 100,
name: "名字4"
},{
amount: 10,
name: "名字5"
},{
amount: 690,
corpName: "名字6"
},{
amount: 190,
name: "名字7"
},{
amount: 230,
name: "名字8"
}
]
}
},
created() {
const clientWidth = document.documentElement.clientWidth
if (clientWidth < 990) {
this.chartWidth = document.documentElement.clientWidth - 20 + 'px'
} else {
this.chartWidth = 'auto'
}
},
methods: {
drawRing() {
this.$refs.chart_histogram.echarts.resize()
}
}
}
</script>
展示效果