使用 Anychart 8.3+ 时,我正在使用树状图chart.listen('drillChange')
侦听器来获取单击元素的信息。
注意:我需要使用示例中所示的e.current.get('name')
,而不是按照树状图listen()
文档使用e.currentTarget
。但是,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
});
下面是指向示例代码的链接,其中显示了未定义的e.currentTarget
、定义的e.current.get('name')
和向下钻取路径值落后一步。
https://playground.anychart.com/AeI6bUhK/7
提前感谢!
e.currentTarget
是默认字段,在某些上下文中可以未定义。getDrillDownPath()
函数返回当前级别的路径。您可以从e.current.get('name')
获得的当前级别。因此,出于您的目的,您可以获得如下的完整路径:
chart.title("Treemap: Interactivity (Drillchange)" +
"<br><br>Path: " + text + "\" + e.current.get('name')
);