admin-fe/src/views/dashboard/admin/components/BarChart.vue

107 lines
2.3 KiB
Vue
Raw Normal View History

2017-06-30 10:43:04 +00:00
<template>
<div :class="className" :style="{height:height,width:width}"/>
2017-06-30 10:43:04 +00:00
</template>
2017-07-06 09:56:17 +00:00
2017-06-30 10:43:04 +00:00
<script>
2017-08-22 07:43:34 +00:00
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils'
2017-08-22 07:43:34 +00:00
2017-11-17 06:57:39 +00:00
const animationDuration = 6000
2017-11-17 09:51:41 +00:00
2017-08-22 07:43:34 +00:00
export default {
props: {
className: {
type: String,
default: 'chart'
2017-06-30 10:43:04 +00:00
},
2017-08-22 07:43:34 +00:00
width: {
type: String,
default: '100%'
2017-06-30 10:43:04 +00:00
},
2017-08-22 07:43:34 +00:00
height: {
type: String,
default: '300px'
}
},
2019-02-22 18:06:48 +00:00
data: function() {
2017-08-22 07:43:34 +00:00
return {
chart: null
}
},
mounted() {
this.initChart()
2018-09-03 07:03:00 +00:00
this.__resizeHandler = debounce(() => {
if (this.chart) {
this.chart.resize()
}
}, 100)
2018-09-03 07:03:00 +00:00
window.addEventListener('resize', this.__resizeHandler)
2017-08-22 07:43:34 +00:00
},
beforeDestroy() {
if (!this.chart) {
return
}
2018-09-03 07:03:00 +00:00
window.removeEventListener('resize', this.__resizeHandler)
2017-08-22 07:43:34 +00:00
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el, 'macarons')
2017-06-30 10:43:04 +00:00
2017-08-22 07:43:34 +00:00
this.chart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: { // 坐标轴指示器,坐标轴触发有效
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
}
},
grid: {
2017-11-16 09:25:28 +00:00
top: 10,
left: '2%',
right: '2%',
2017-08-22 07:43:34 +00:00
bottom: '3%',
containLabel: true
},
xAxis: [{
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisTick: {
alignWithLabel: true
}
}],
yAxis: [{
2017-11-16 09:25:28 +00:00
type: 'value',
axisTick: {
show: false
}
2017-08-22 07:43:34 +00:00
}],
series: [{
name: 'pageA',
type: 'bar',
stack: 'vistors',
barWidth: '60%',
data: [79, 52, 200, 334, 390, 330, 220],
animationDuration
}, {
name: 'pageB',
type: 'bar',
stack: 'vistors',
barWidth: '60%',
data: [80, 52, 200, 334, 390, 330, 220],
animationDuration
}, {
name: 'pageC',
type: 'bar',
stack: 'vistors',
barWidth: '60%',
data: [30, 52, 200, 334, 390, 330, 220],
animationDuration
}]
})
2017-06-30 10:43:04 +00:00
}
2017-08-22 07:43:34 +00:00
}
2017-06-30 10:43:04 +00:00
}
</script>