<template>
<div id="area-bar" class="container"/>
</template>
<script>
import * as echarts from 'echarts';
var SData1 = [10, 13, 1, 18, 15, 19, 18, 10, 16, 14, 10, 12,10, 13, 10, 18, 15, 19, 18, 10, 16, 14, 10, 12];
var SData = [20, 13, 30, 28, 35, 29, 18, 20, 26, 24, 30, 32,20, 13, 3, 28, 35, 29, 18, 2, 26, 24, 3, 32];
var SData2 = [12,16,18,19,14,16,12,16,18,19,14,16,12,16,18,19,14,16,12,16,18,19,14,16]
export default {
name: 'AreaBar',
data() {
return {
timer: null,
height: '0',
extend: {
legend: {
textStyle: {
color: '#cce9ff',
fontWeight: 'bold'
},
lineStyle: {
width: 5
},
data: ['重大', '较大', '一般']
},
tooltip: {
trigger: 'axis',
axisPointer: {
label: {
backgroundColor: '#82b4dc'
}
}
},
grid: {
left: '1%',
right: '1%',
bottom: '1%',
top: '15%',
containLabel: true
},
xAxis: {
type: 'category',
axisLabel: {
color: '#cce9ff'
},
axisTick: { show: false },
axisLine: {
lineStyle: {
color: '#cce9ff'
}
},
data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23']
},
yAxis: {
position: 'left',
type: 'value',
axisLabel: {
color: '#cce9ff'
},
axisLine: {
lineStyle: {
color: '#cce9ff'
}
}
},
dataZoom: [{
show: false,
xAxisIndex: [0],
type: 'slider',
startValue: 0,
endValue: 4
}],
series: [
{
label: {
color: '#cce9ff',
show: true,
align: 'center',
verticalAlign: 'middle',
position: 'top',
distance: 5
},
name: '重大',
type: 'bar',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 1, color: 'rgba(184,215,243,0.8)' },
{ offset: 0.3, color: '#188df0cc' },
{ offset: 0, color: '#188df0cc' }
])
},
emphasis: {
focus: 'series',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#2378f7cc' },
{ offset: 0.7, color: '#2378f7cc' },
{ offset: 1, color: 'rgba(184,215,243,0.8)' }
])
}
},
data: SData
},
{
label: {
color: '#cce9ff',
show: true,
align: 'center',
verticalAlign: 'middle',
position: 'top',
distance: 5
},
name: '较大',
type: 'bar',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 1, color: 'rgba(195,250,235,0.8)' },
{ offset: 0.3, color: 'rgba(0,253,232,0.8)' },
{ offset: 0, color: 'rgba(0,178,172,0.8)' }
])
},
emphasis: {
focus: 'series',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: 'rgba(0,253,232,0.8)' },
{ offset: 0.7, color: 'rgba(0,178,172,0.8)' },
{ offset: 1, color: 'rgba(195,250,235,0.8)' }
])
}
},
data: SData1
},
{
label: {
color: '#cce9ff',
show: true,
align: 'center',
verticalAlign: 'middle',
position: 'top',
distance: 5
},
name: '一般',
type: 'bar',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 1, color: 'rgba(250,224,198,0.8)' },
{ offset: 0.3, color: '#ff9913cc' },
{ offset: 0, color: '#FFB005CC' }
])
},
emphasis: {
focus: 'series',
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#ff9913cc' },
{ offset: 0.7, color: '#FFB005CC' },
{ offset: 1, color: 'rgba(250,224,198,0.8)' }
])
}
},
data: SData2
}
]
}
}
},
mounted() {
var myChart = echarts.init(document.getElementById('area-bar'))
const that = this
this.timer = setInterval(function() {
// 每次向后滚动一个,最后一个从头开始。
if (that.extend.dataZoom[0].endValue === 23) {
that.extend.dataZoom[0].endValue = 4
that.extend.dataZoom[0].startValue = 0
} else {
that.extend.dataZoom[0].endValue = that.extend.dataZoom[0].endValue + 1
that.extend.dataZoom[0].startValue = that.extend.dataZoom[0].startValue + 1
}
myChart.setOption(that.extend, true)
}, 2000)
myChart.clear()
myChart.setOption(that.extend, true)
window.addEventListener('resize', function() {
myChart.resize()
})
},
beforeDestroy() {
clearInterval(this.timer)
this.timer = null
},
methods: {
}
}
</script>
<style lang="scss" scoped>
.container {
width: 100%;
height: 200px;
}
</style>