加上true
this.$nextTick(() => {
this.chart.setOption(options, true)
})
<template>
<div :class="className" :style="{ height: height, width: width }" />
</template>
<script>
import echarts from './mixins/echarts'
import resize from './mixins/resize'
import common from './mixins/common'
import { exportpic } from '@/common/js/gem'
import { mapState } from 'vuex'
const textCol = window.getComputedStyle(document.documentElement).getPropertyValue("--infoCol").trim();
export default {
name: 'LineBarChart',
mixins: [resize, common],
props: {
className: {
type: String,
default: 'chart',
},
title: {
type: String,
default: '',
},
titlePosition: {
type: String,
default: 'center',
},
width: {
type: String,
default: '100%',
},
height: {
type: String,
default: '100%',
},
canScreenfull: {
type: Boolean,
default: false,
},
autoResize: {
type: Boolean,
default: true,
},
legend: {
type: Object,
default () {
return {
// right: '280px',
top: '-5px',
textStyle: {
color: textCol //字体颜色
},
}
}
},
magicType: {
type: Object,
default () {
return {}
}
},
chartData: {
type: [Object, Array],
default () {
return {}
},
},
},
computed: {
...mapState(['resurfacing'])
},
methods: {
setOptions (datas) {
var lastNonNullElement
var xAxisPosition
for (var i = datas.source.length - 1; i >= 0; i--) {
if (datas.source[i][1] !== null) {
lastNonNullElement = datas.source[i] || []
xAxisPosition = i // 计算并赋值X轴位置(这里是索引)
break
}
}
const options = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: this.resurfacing == 'darkTheme' ? '#6a7985' : '#fFF',
},
},
},
toolbox: {
show: true,
// feature: {
// magicType: this.magicType,
// },
// right: '120px',
top: '',
},
legend: this.legend,
dataset: {
source: datas.source,
},
grid: {
left: 0,
right: 0,
bottom: '5%',
top: '30%',
containLabel: true,
},
xAxis: [
{
type: 'category',
splitLine: {
show: false
},
axisLine: {
lineStyle: {
color: this.resurfacing == 'darkTheme' ? '#6a7985' : '#fFF',
}
}
},
],
yAxis: [
{
type: 'value',
splitLine: {
show: false
},
axisLine: {
lineStyle: {
color: this.resurfacing == 'darkTheme' ? '#6a7985' : '#fFF',
}
}
},
],
series: [
{
type: datas.chartType,
markPoint: {
data: [
{
type: 'max',
name: '最大值',
label: {
show: true,
color: '#fff',
},
},
{
type: 'min',
name: '最小值',
label: {
show: true,
color: '#fff',
},
},
{
yAxis: lastNonNullElement ? lastNonNullElement[1] : [],
value: lastNonNullElement ? lastNonNullElement[1] : [],
xAxis: lastNonNullElement ? lastNonNullElement[0] : [],
label: {
show: true,
color: '#fff',
},
itemStyle: {
color: '#00FF7B',
},
},
],
},
areaStyle: {
opacity: 0.3,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: '#AFE9E6',
},
{
offset: 1,
color: '#ffffff',
},
]),
},
smooth: true,
itemStyle: {
color: '#AFE9E6',
},
emphasis: {
focus: 'series',
},
},
],
}
this.$nextTick(() => {
this.chart.setOption(options, true)
})
},
},
}
</script>