
<template>
<div>
<div id="echarts_content"></div>
</div>
</template>
<script>
export default {
data() {
return {}
},
mouted() {
this.initCharts()
},
methods: {
initCharts() {
var myChart = this.$echarts.init(document.getElementById('echarts_content'))
var data = henameSums
var className = henameList
var colorList = ['#FF6600', '#FAC450', '#F7A729', '#00B050', '#0a7c3d']
var option = {
title: {
left: 'left',
top: '2%',
text: 'T超级',
textStyle: {
fontWeight: 'bold',
color: '#6666',
fontSize: 18,
fontFamily: 'Microsoft YaHei'
}
},
grid: {
left: '2%',
right: '1%',
bottom: '1%',
top: '5%',
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'none'
}
xAxis: {
show: false,
type: 'value'
},
yAxis: [
{
type: 'category',
inverse: true,
triggerEvent: true,
axisLabel: {
show: true,
textStyle: {
color: '#5A5E66'
},
formatter: function (value) {
var val = ''
if (value.length > 5) {
val = value.substr(0, 5) + '...'
return val
} else {
return value
}
}
},
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLine: {
show: false
},
data: className
},
{
type: 'category',
inverse: true,
axisTick: 'none',
axisLine: 'none',
show: true,
axisLabel: {
textStyle: {
color: '#5A5E66',
fontSize: '12',
fontFamily: 'Microsoft YaHei',
fontWeight: 'bold'
},
formatter: function (value) {
return value + ' 次'
}
},
data: data
}
],
series: [
{
name: '次数',
type: 'bar',
zlevel: 1,
itemStyle: {
normal: {
barBorderRadius: 0,
color: params => {
return colorList[params.dataIndex]
}
}
},
barWidth: 18,
data: data
},
{
name: '图例1',
type: 'bar',
barWidth: 18,
barGap: '-120%',
itemStyle: {
normal: {
color: '#fff',
barBorderRadius: 0
}
}
}
]
}
myChart.setOption(option)
window.addEventListener('resize', function () {
myChart.resize()
})
extension(myChart)
function extension(myChart) {
var elementDiv = document.getElementById('extension')
if (!elementDiv) {
var div = document.createElement('div')
div.setAttribute('id', 'extension')
div.style.display = 'block'
document.querySelector('html').appendChild(div)
}
myChart.on('mouseover', function (params) {
if (params.componentType == 'yAxis') {
var elementDiv = document.querySelector('#extension')
var elementStyle =
'position: absolute;z-index: 99999;color: #fff;font-size: 12px;padding: 5px;display: inline;border-radius: 4px;background-color: #303133;box-shadow: rgba(0, 0, 0, 0.3) 2px 2px 8px'
elementDiv.style.cssText = elementStyle
elementDiv.innerHTML = params.value
document.querySelector('html').onmousemove = function (event) {
var elementDiv = document.querySelector('#extension')
var xx = event.pageX - 10
var yy = event.pageY + 15
elementDiv.style.top = yy + 'px'
elementDiv.style.left = xx + 'px'
}
}
})
myChart.on('mouseout', function (params) {
if (params.componentType == 'yAxis') {
var elementDiv = document.querySelector('#extension')
elementDiv.style.cssText = 'display:none'
}
})
}
}
}
}
</script>
<style lang="less" scoped>
#echarts_content{
width: 100%;
height: 100%;
}
</style>