2025-06-19 09:43:36 +08:00
|
|
|
<template>
|
|
|
|
<div :class="className" :style="{height:height,width:width}" />
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import * as echarts from 'echarts'
|
|
|
|
require('echarts/theme/macarons') // echarts theme
|
|
|
|
import resize from './mixins/resize'
|
|
|
|
|
|
|
|
const animationDuration = 6000
|
|
|
|
|
|
|
|
export default {
|
|
|
|
mixins: [resize],
|
|
|
|
props: {
|
|
|
|
className: {
|
|
|
|
type: String,
|
|
|
|
default: 'chart'
|
|
|
|
},
|
|
|
|
width: {
|
|
|
|
type: String,
|
|
|
|
default: '100%'
|
|
|
|
},
|
|
|
|
height: {
|
|
|
|
type: String,
|
|
|
|
default: '300px'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
chart: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.initChart()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
if (!this.chart) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.chart.dispose()
|
|
|
|
this.chart = null
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
initChart() {
|
2025-07-04 17:29:32 +08:00
|
|
|
this.chart = echarts.init(this.$el)
|
2025-06-19 09:43:36 +08:00
|
|
|
|
|
|
|
this.chart.setOption({
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: { // 坐标轴指示器,坐标轴触发有效
|
|
|
|
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
top: 10,
|
|
|
|
left: '2%',
|
|
|
|
right: '2%',
|
|
|
|
bottom: '3%',
|
|
|
|
containLabel: true
|
|
|
|
},
|
|
|
|
xAxis: [{
|
|
|
|
type: 'category',
|
2025-07-04 17:29:32 +08:00
|
|
|
data: ['美国', '德国', '日本', '英国', '法国'],
|
2025-06-19 09:43:36 +08:00
|
|
|
axisTick: {
|
|
|
|
alignWithLabel: true
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
yAxis: [{
|
|
|
|
type: 'value',
|
|
|
|
axisTick: {
|
|
|
|
show: false
|
|
|
|
}
|
|
|
|
}],
|
2025-07-04 17:29:32 +08:00
|
|
|
series: [ {
|
|
|
|
name: '',
|
2025-06-19 09:43:36 +08:00
|
|
|
type: 'bar',
|
|
|
|
stack: 'vistors',
|
|
|
|
barWidth: '60%',
|
2025-07-04 17:29:32 +08:00
|
|
|
data: [
|
|
|
|
{
|
|
|
|
value: 330,
|
|
|
|
itemStyle: {
|
|
|
|
color: '#1D8FFF'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 200,
|
|
|
|
itemStyle: {
|
|
|
|
color: '#1D8FFF'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 150,
|
|
|
|
itemStyle: {
|
|
|
|
color: '#1D8FFF'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 140,
|
|
|
|
itemStyle: {
|
|
|
|
color: '#1D8FFF'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 100,
|
|
|
|
itemStyle: {
|
|
|
|
color: '#1D8FFF'
|
|
|
|
}
|
|
|
|
}],
|
2025-06-19 09:43:36 +08:00
|
|
|
animationDuration
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|