The problem you were having is that your original data, allData
, was being changed by the computation of links and nodes at each data change iteration. After all, you set links = cloneData[0][selectedCode];
. You need to clone allData
before each data change.
function codeChange() {
selectedCode = this.value;
cloneData = clone(allData); // added
clearNodes();
updateNodes();
}
Here is a FIDDLE with all the changes to make it work. I borrowed the clone function from this SO question.
NOTE: I also removed one of your dropdown choices since you only have 3 sets of data in allData
. That was not the cause of your problems, per above, but it was throwing errors whenever you selected the inexistent set.