echart 变化数据的处理,随后端数据变化而变化

const tenpData = [];
  (qryTrendsData || []).forEach((element) => { // 获取所有detail数据
    tenpData.push(...element?.industryDetails);
  });

  const tempFlag = tenpData.every(item => item?.industryProportion === 0)

  // 将数据处理成echart需要的数据
  const datas = new Map();
  (tenpData || []).forEach((el) => {
    const old = datas.get(el.industryName) || []; // 之前存在的数据
    datas.set(el.industryName, [...old, (el.industryProportion * 100).toFixed(2)]); // 前 后合并 -- 现有数据
  });

  // 重构数据结构
  const result = [];
  (Array.from(datas) || []).forEach((el) => {
    result.push({
      key: el[0],
      value: el[1],
    });
  });

  const newQryTrendsData = [];
  const lastQryTrendsData = [];
  const other = [];
  (result || []).forEach((e) => {
    // 判断是否展示,还是在其它内
    const flag = showData.includes(e.key);
    if (flag) {
      newQryTrendsData.push(e);
    } else {
      other.push(e.value);
    }
  });

  // 其它数据的处理
  let otherA;
  if (other.length > 0) {
    otherA = other.reduce((r, a) => {
      (a || []).forEach((b, i) => {
        r[i] = (r[i] || 0) + Number(b);
      });
      return r;
    }, []);
  }

  // 配置项选择的行业没有数据,也进行展示
  (showData || []).forEach((e) => {
    if (newQryTrendsData.length !== 0) {
      (newQryTrendsData || []).forEach((v) => {
        lastQryTrendsData.push(e === v.key ? v : { key: e, value: [] });
      });
    } else {
      lastQryTrendsData.push({ key: e, value: [] });
    }
  });

  const obj = {};
  obj.key = '其他';
  obj.value = otherA || [];
  lastQryTrendsData.push(obj);

  const series = [];
  for (let i = 0; i < lastQryTrendsData?.length; i++) {
    series.push({
      name: lastQryTrendsData[i]?.key,
      type: 'line',
      stack: 'Total',
      symbol: 'none', // 取消折点圆圈
      smooth: true, // 折线平滑
      showSymbol: false,
      yAxisIndex: 0,
      emphasis: {
        disabled: true,
        focus: 'none',
      },
      areaStyle: {},
      data: lastQryTrendsData[i]?.value,
    });
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值