Skip to content

动态更新与动画

入场动画

图表首次渲染和数据变更时自动播放入场动画(约 500ms):

  • 柱图:从底部向上生长
  • 饼/环图:扇区从起始角展开
  • 进度环:弧线从起始角展开
  • 其他:淡入

通过 props 更新

直接修改绑定的 options 对象,会触发入场动画重新播放:

html
<x-chart :options="chartOptions" />
typescript
// 切换数据
chartOptions = { data: newData, series: [...] }

通过 ref 方法更新

html
<x-chart ref="chartRef" :options="opts" />
typescript
const chartRef = ref()

// 更新配置(触发入场动画)
chartRef.value.setOptions({
  data: newData,
  series: [{ type: 'bar', xField: 'x', yField: 'y' }]
})

// 仅重绘(不触发动画)
chartRef.value.redraw()

混合图表

同一图表中可以混合多种系列类型:

typescript
{
  data: [...],
  series: [
    { type: 'bar', xField: 'month', yField: 'sales' },
    { type: 'line', xField: 'month', yField: 'profit', color: '#ef4444' }
  ]
}

柱图和折线会共享同一坐标轴,自动合并 Y 轴范围。

最近更新