You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AnyChart堆叠数据(如水瀑布图)中获取正确的双层索引?

解决AnyChart堆叠/瀑布图pointClick事件获取双索引的问题

在AnyChart的堆叠类图表(比如水瀑布图)中,仅用e.iterator.getIndex()只能拿到当前点击点所属的列(类别)索引,同一列内的所有点都会返回相同值。要同时获取列索引和列内元素的索引,可通过以下两种方式实现:

方法1:通过事件参数的point对象获取系列索引

chart.listen("pointClick", function(e){
  // 获取列(类别)索引
  const columnIndex = e.iterator.getIndex();
  // 获取列内元素对应的系列索引
  const innerIndex = e.point.seriesIndex;
  console.log(`列索引:${columnIndex},列内元素索引:${innerIndex}`);
});

方法2:通过iterator对象直接获取系列索引

chart.listen("pointClick", function(e){
  const columnIndex = e.iterator.getIndex();
  // 直接从iterator获取系列索引
  const innerIndex = e.iterator.getSeriesIndex();
  console.log(`列索引:${columnIndex},列内元素索引:${innerIndex}`);
});

两种方式都能准确拿到区分同一列内不同元素的索引,其中seriesIndex对应系列在图表中的顺序,也就是同一列内元素的排列顺序索引。

内容的提问来源于stack exchange,提问作者jparanich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 09:45:28