问题
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:
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')
);
来源:https://stackoverflow.com/questions/54017423/anychart-treemap-drillchange-current-event-out-of-sync-with-getdrilldownpath