简体   繁体   中英

Trigger legend click event in nvd3 using jquery?

I'm using nvd3 for a multi-bar chart, and I'd like to make the chart redraw when the user clicks the other html on my page. I tried using jQuery to select the "Stream0" legend circle on the nvd3 homepage ( http://nvd3.org/ ) and click it using this snippet in the console:

$($('g.nv-series')[0]).click()

For reasons that I hope will be immediately obvious to people more knowledgeable about javascript, nothing happens. Is it something to do with event delegation?

http://nvd3.org/

you can try this:

chart.legend.dispatch.legendClick = function(d, i){
//redraw
};

It will append your own method to the legend; it works for pie chart not sure if works for the line chart;

Maybe there is some help in this. Two charts, one pie, one stack but only showing legends on pie. The data is not identical but the legends are.. Want to update both on clicking pie legends.

        chart.legend.dispatch.on('stateChange.pie', function(d,i){
            setTimeout(function() {
                stackedAreaChart.dispatch.changeState(d,i);
                stackedAreaChart.update();
            }, 100);
        }); 

Note: using the ".pie" will extend the (library) stateChange event (not overwrite it) The other chart stackedAreaChart has to be in the scope. Note there is a changeState event and a stateChange, best is to look at the un-minified nvd3 js file..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM