前端客户端职业研发 2024-10-17 10:57 采纳率: 50%
浏览 21
已结题

【Echarts动态排序图,series使用背景色更新动画,背景底色不同步跟随柱子动画】

【Echarts动态排序图,series使用背景色更新动画,背景底色不同步跟随柱子动画】

img

https://echarts.apache.org/examples/zh/editor.html?c=bar-race

series下面添加了showBackground属性,动画时底色背景不同步跟随柱图

showBackground: true,
backgroundStyle: {
   borderRadius: 9,
   color: 'RGB(255,199,91, 0.2)'
}

const data = [];
for (let i = 0; i < 5; ++i) {
  data.push(Math.round(Math.random() * 200));
}
option = {
  xAxis: {
    max: 'dataMax'
  },
  yAxis: {
    type: 'category',
    data: ['A', 'B', 'C', 'D', 'E'],
    inverse: true,
    animationDuration: 300,
    animationDurationUpdate: 300,
    max: 4 // only the largest 3 bars will be displayed
  },
  series: [
    {
      realtimeSort: true,
      name: 'X',
      type: 'bar',
      data: data,
      label: {
        show: true,
        position: 'right',
        valueAnimation: true
      },
      showBackground: true,
      backgroundStyle: {
          borderRadius: 9,
          color: 'RGB(255,199,91, 0.2)'
      },
      animation: true
    }
  ],
  legend: {
    show: true
  },
  animationDuration: 0,
  animationDurationUpdate: 3000,
  animationEasing: 'linear',
  animationEasingUpdate: 'linear',
  animation: true
};
function run() {
  for (var i = 0; i < data.length; ++i) {
    if (Math.random() > 0.9) {
      data[i] += Math.round(Math.random() * 2000);
    } else {
      data[i] += Math.round(Math.random() * 200);
    }
  }
  myChart.setOption({
    series: [
      {
        type: 'bar',
        data
      }
    ]
  });
}
setTimeout(function () {
  run();
}, 0);
setInterval(function () {
  run();
}, 2000);
  • 写回答

1条回答 默认 最新

  • 码海探路 2024-10-18 17:14
    关注

    换一种方式实现,用两个柱状图叠加在也可以实现这种效果

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月6日
  • 已采纳回答 10月29日
  • 修改了问题 10月17日
  • 创建了问题 10月17日