I'm trying to build a toggle switch to change between two different data sets on a Highcharts Sankey chart. The data is more or less updating properly, however the nodes don't get destroyed on each chart.update() so the new set of nodes are redrawn on top of the old set.
Here is the update part of the code:
$('#yearToggle').click(function() {
if (mySankey.title.textStr == 'Tomorrow') {
myData = myData2;
myNodes = myNodes2;
myYear = 'Today'
} else {
myData = myData1;
myNodes = myNodes1;
myYear = 'Tomorrow'
};
mySankey.update({
series: {
data: myData,
nodes: myNodes
},
title: {
text: myYear
}
});
});
I'm sure there are more elegant ways to handle the toggle click portion, but my key concern is the correct updating of the node object within the series. Any help would be appreciated.
Here's the full fiddle: http://jsfiddle.net/j7kwrctn/3/
EDIT: Here's my updated fiddle that uses .destroy() on the nodes prior to updating the data. This works, but isn't ideal as it means there's no smooth animation, which is very helpful in showing what has changed by how much: http://jsfiddle.net/0ex7rpfh/2/