Accepted answer

For each of your data series that you want disabled, just do:


nvd3 does not do everything, but if you are willing to peruse the code it is actually quite flexible. I discovered this by finding this line in the source of several of the chart models:

state.disabled = { return !!d.disabled });


You could start out with a hidden chart and try something like this:

// Array of series you want to hide
var hidden = [0, 2];

// Dispatch click event to each element
var e = document.createEvent('UIEvents');
e.initUIEvent('click', true, true);'.nv-legend')
  .filter(function(d, i){return hidden.indexOf(i) !== -1;})

Once this finishes, unhide your chart and the series will be disabled.


You can change which streams are enabled/disabled by using the chart.state() object. For example:

// Assuming your chart is called 'chart'
var state = chart.state();

for(var i=0; i < state.disabled.length; i++) {
  state.disabled[i] = ...LOGIC RETURNING TRUE OR FALSE...;



After reading this answer I still had to do some more reading in order for me to understand how to set a stream disabled from my JSON data-stream for the graphs.

The example below is what solved it for me disabled: true

    key: "something",
    disabled: true,
    values: [...]

Related Query

More Query from same tag