首页 > 解决方案 > AnyChart Treemap DrillChange 当前事件与 getDrilldownPath 不同步

问题描述

对于 Anychart 8.3+,我正在使用 TreeMapchart.listen('drillChange')侦听器来获取单击元素的信息。

注意:我需要按照示例e.current.get('name')中所示使用,而不是按照 Treemap文档。但是,该值似乎是一个事件单击。为什么是这样?e.currentTargetlisten()getDrillDownPath()

chart.listen("drillChange", function(e){
  // get the drilldown path and convert it to a string
  var text = printPath(chart.getDrilldownPath());

  // set the chart title
  chart.title().useHtml(true);
  chart.title("Treemap: Interactivity (Drillchange)" +
    "<br><br>currentTarget: " + e.currentTarget + 
    "<br><br>current.get('name'): " + e.current.get('name') + 
    "<br><br>Path: " + text
});

下面是示例代码的链接,显示 undefined e.currentTarget、 definede.current.get('name')和向下钻取路径值落后一步。

https://playground.anychart.com/AeI6bUhK/7

提前致谢!

标签: listenertreemapdrilldownanychartanychart-8.2

解决方案


e.currentTarget是在某些情况下可以未定义的默认字段。该getDrillDownPath()函数返回当前级别的路径。您可以从中获得的当前级别e.current.get('name')。因此,为了您的目的,您可以获得这样的完整路径:

  chart.title("Treemap: Interactivity (Drillchange)" +
    "<br><br>Path: " + text + "\\" + e.current.get('name')
  );

推荐阅读