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>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要让echarts饼图实现动态变化动画,可以使用echarts提供的setOption方法来更新数据,然后通过动画效果来呈现数据变化的效果。下面是一个简单的例子: ```javascript // 初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 初始数据 var data = [ {value: 335, name: '直接访问'}, {value: 310, name: '邮件营销'}, {value: 234, name: '联盟广告'}, {value: 135, name: '视频广告'}, {value: 1548, name: '搜索引擎'} ]; // 配置项 var option = { title: { text: '访问来源', subtext: '纯属虚构', left: 'center' }, tooltip: { trigger: 'item', formatter: '{a} <br/>{b} : {c} ({d}%)' }, legend: { orient: 'vertical', left: 'left', data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎'] }, series: [ { name: '访问来源', type: 'pie', radius: '55%', center: ['50%', '60%'], label: { show: false, position: 'center' }, data: data, emphasis: { label: { show: true, fontSize: '30', fontWeight: 'bold' } } } ] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); // 动态更新数据 setInterval(function () { data.forEach(function (item) { item.value = Math.round(Math.random() * 1000); }); myChart.setOption({ series: [{ data: data }] }); }, 2000); // 每隔2秒更新一次数据 ``` 在这个例子中,我们首先通过初始化echarts实例和配置项来显示初始的饼图。然后使用setInterval函数来定时更新数据,每隔2秒就更新一次数据。在每次数据更新后,我们使用setOption方法来将新数据应用到饼图中,并使用动画效果呈现数据变化的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Mars空港

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

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

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

打赏作者

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

抵扣说明:

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

余额充值