Accepted answer

If you want to read all the data once, you should store it in your global DATASET variable, just as you show in your code fragment. But instead of placing the update logic in your main script flow, put it inside an update(...) function, and call that from the d3.json callback, too... something like this (untested):

var DATASET; // global

d3.json("file.json", function(data) {
    // data is loaded, save the full set
    DATASET = data;
    // filter the initial subset
    var subdata = data.filter(...);
    // now update the graph

function updateGraph(data) {
    // when invoked without any data, use the full dataset
    var newdata = (data == null ? DATASET : data);

    // data rendering logic starts here...

This saves the full dataset in a global variable, draws the inital graph with a filtered subset of the data, and also allows you to change which data is shown by using a different filter before calling the function again.

Related Query

More Query from same tag