AnyChart Treemap drillChange current event out of

2019-08-18 03:26发布

With Anychart 8.3+ I am using the TreeMap chart.listen('drillChange') listener to obtain a clicked element's information.

Note: I needed to use e.current.get('name') as shown in an example, instead of e.currentTarget as per Treemap listen() documentation. However the getDrillDownPath() value seems to be one event-click behind. Why is this?

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
});

Below is a link to sample code, showing the undefined e.currentTarget, the defined e.current.get('name'), and the drilldown path value being one step behind.

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

Thanks in advance!

1条回答
别忘想泡老子
2楼-- · 2019-08-18 04:13

The e.currentTarget is the default field which in some context can be undefined. The getDrillDownPath() function returns the path to the current level. The current level you can get from e.current.get('name'). So, for your purpose the full path you can get like this:

  chart.title("Treemap: Interactivity (Drillchange)" +
    "<br><br>Path: " + text + "\\" + e.current.get('name')
  );
查看更多
登录 后发表回答