You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
frontend/src/views/stritl/chartFiles/horizontalBar.vue

76 lines
2.3 KiB
Vue

2 years ago
<template>
<div id="myTopChart" ref="barChart" :style="boxStyle"></div>
</template>
<script>
export default {
props: ['legendData', 'seriesData', 'boxStyle'],
data() {
return {};
},
mounted() {
this.$nextTick(function () {
this.drawBar();
});
},
methods: {
drawBar() {
// 基于准备好的dom初始化echarts实例
var myChart = this.$echarts.init(this.$refs.barChart);
// 绘制图表
myChart.setOption({
color: ['#80FFA5', '#00DDFF', '#37A2FF', '#FF0087', '#FFBF00'],
tooltip: {},
legend: {},
grid: {
left: '6%',
right: '5%',
top: '7%',
bottom: '10%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01]
},
yAxis: {
type: 'category',
data: this.legendData
},
series: [
{
type: 'bar',
barWidth: 25,
itemStyle: {
color: new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [
{ offset: 0, color: '#00DDFF' },
{ offset: 1, color: '#80FFA5' }
])
},
data: this.seriesData
}
]
});
window.addEventListener('resize', () => {
// 第六步执行echarts自带的resize方法即可做到让echarts图表自适应
myChart.resize();
});
}
},
watch: {
legendData(val, old) {
this.drawBar();
}
},
beforeDestroy() {
/* resize
容易导致内存泄漏和额外CPU或GPU占用哦*/
window.removeEventListener('resize', () => {
myChart.resize();
});
}
};
</script>
<style lang="less">
#myTopChart {
}
</style>