lg_frontend/components/charts/PeakEnergyUseChart.vue

181 lines
3.6 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!--能源使用情况-->
<template>
<div id="charts" ref="charts">
</div>
</template>
<script>
import * as echarts from 'echarts'
import {EleResize} from '@/utils/esresize';
const lodash = require('lodash')
export default {
name: 'PeakEnergyUseChart',
props: {
dataSource: {
type: Array,
default: () => []
},
color: {
type: Array,
default: () => [
'#00F6FF',
'#007CFF',
'#FDBD00'
]
}
},
data() {
return {}
},
watch: {
dataSource: {
deep: true,
immediate: true,
handler(value) {
if (value.length) {
this.$nextTick(() => {
this.init()
})
}
}
}
},
mounted() {
this.$nextTick(() => {
this.init()
})
},
methods: {
init() {
let myCharts = echarts.init(this.$refs.charts)
let barCharts = this.$refs.charts
// 复制代码
let color = this.color;
let xAxisData = this.dataSource.map(item => item.name);
let yAxisData1 = this.dataSource.map(item => item.value1);
let yAxisData2 = this.dataSource.map(item => item.value2);
let option = {
color: color,
legend: {
top: 0,
right: 0,
itemWidth: 11,
itemHeight: 11,
icon: 'circle',
textStyle: {
color: '#B8D3F1',
fontSize: 12,
}
},
tooltip: {
trigger: 'axis',
},
grid: {
top: 50,
bottom: 10,
left: 20,
right: 20,
containLabel: true,
},
xAxis: [
{
type: 'category',
boundaryGap: true,
axisLabel: {
fontSize: 12,
color: '#B8D3F1'
},
axisLine: {
show: true,
lineStyle: {
color: 'rgba(176,215,255,0.40)',
},
},
axisTick: {
show: false
},
data: xAxisData,
},
],
yAxis: [
{
type: 'value',
position: 'left',
splitNumber: 5,
name: '单位t',
axisLabel: {
fontSize: 12,
color: '#B8D3F1'
},
nameTextStyle: {
color: '#B8D3F1',
fontSize: 12,
lineHeight: 10,
},
// 分割线
splitLine: {
show: false,
lineStyle: {
color: 'rgba(176,215,255,0.40)',
type: 'dashed'
},
},
axisLine: {
show: false,
},
axisTick: {
show: false,
},
}
],
series: [
{
name: 'VOC',
type: 'line',
smooth: false,
zlevel: 3,
symbol: 'none', //数据交叉点样式
data: yAxisData1,
lineStyle: {
width: 3,
}
},
{
name: 'SEMES',
type: 'line',
smooth: false,
zlevel: 3,
symbol: 'none', //数据交叉点样式 (实心点)
data: yAxisData2,
lineStyle: {
width: 3,
}
}
],
};
myCharts.setOption(option)
let listener = function () {
myCharts.resize()
}
EleResize.on(barCharts, listener)
}
}
}
</script>
<style scoped lang="less">
#charts {
height: 100%;
width: 100%;
}
</style>