Echarts的数据变化但是legend没有变化

 加上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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mars空港

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>