Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable some streams by default in a nvd3 Simple Line Chart?

I have several lines and I know that clicking on the "dot" in the legend will hide/show it.

However, I need to start with some of the lines being disabled and not displayed, and the user will have to click on the dot in the legend to show it on the graph.

(eg. I graph the number of questions on stackoverflow per language, but with C, PHP and javascript disabled by default). the graph only shows python, ruby... but on the legend, you have all the languages, including C, PHP and js with these 3 being disabled.

I haven't found a method/attribute for each data serie to set the default show/hide status. Am I missing something?

like image 397
xavier Avatar asked Jun 06 '13 12:06

xavier


2 Answers

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: [...]
    }
like image 68
user3294155 Avatar answered Sep 19 '22 13:09

user3294155


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...;
}

chart.dispatch.changeState(state);
chart.update();
like image 24
KurtPreston Avatar answered Sep 18 '22 13:09

KurtPreston