Accepted answer

I may be misinterpreting your question, but it sounds like the user clicks a button, which triggers a change to different CSV source data, but the same drawing action occurs.

If so, I would suggest the following:

(Note: this is all untested pseudo-code. If you create a plunkr for your code we can be exact)

Create an "update" function, which is a named function for the code currently handled by function(d). IE:

function update(d) { d.value = +d.value; ... }

Convert your initial code to : d3.csv("flare.csv", update(d) );

Create the change capability. Something like: function changeDataSource() { d3.csv("flareAlt.csv", update(d) ) ); }

Connect your button to the above function. <button onClick="changeDataSource()">Switch to FlareAlt</button>

Related Query