<template>
<div class="myChart" ref="myChart"></div>
</template>
<style lang="less" scoped>
.myChart{
width: 100px;
height: 190px;
}
</style>
<script>
export default {
mounted() {
this.drawLine()
this.onClickDetail()
},
methods:{
drawLine(){
let _this = this;
let myChartDom = _this.$refs.myChart;
if(myChartDom){
let myChart = _this.$echarts.init(myChartDom);
let option = {
color: ['#5795D0'],
tooltip : {
trigger: 'axis',
axisPointer : {
type : 'shadow'
},
formatter:function(params){
return params[0].name;
}
},
grid: {
left: 45
},
xAxis : [
{
type : 'category',
data : xData,
axisTick: {
alignWithLabel: false
},
axisLine: {show:false},
axisTick: {show:false},
axisLine:{
lineStyle:{
color:'#666666',
}
},
axisLabel: {
interval:0,
rotate:-40
}
}
],
yAxis : [
{
type : 'value',
axisLine: {show:false},
axisTick: {show:false},
min: 0,
max: 100,
interval:20,
axisLabel:{
formatter:'{value}%'
},
axisLine:{
lineStyle:{
color:'#666666',
}
},
splitLine: {
show: true,
lineStyle:{
color: ['#ffffff'],
width: 1,
type: 'solid'
}
}
}
],
dataZoom: [{
type: 'inside',
show: true,
xAxisIndex: 0,
handleSize: 0,
left: '15%',
height: 80,
bottom:'auto',
start: 0,
end: _this.EndPositoin,
showDataShadow: false,
showDetail: false,
fillerColor: 'rgba(255,255,255,.1)',
borderColor: "none",
zoomLock:false,
}],
series : [
{
name:'启用数',
type:'bar',
barWidth: '60%',
data:yData,
label:{
normal:{
show: true,
position: 'top',
textStyle:{
color: '#ccc',
fontSize: 12
},
formatter: '{c}%',
}
}
}
],
};
myChart.setOption(option)
}
},
onClickDetail(){
let _this = this;
let myChart = _this.$echarts.init(_this.$refs.myChart);
myChart.getZr().off('click');
myChart.getZr().on('click', function (params) {
let pointInPixel= [params.offsetX, params.offsetY];
if (myChart.containPixel('grid',pointInPixel)) {
let indexFlg= myChart.convertFromPixel({seriesIndex:0},[params.offsetX, params.offsetY])[0];
}
});
},
}
}
</script>