Trigger legend click event in nvd3 using jquery?

I use nvd3 for a multibyte chart, and I would like the chart to be redrawn when the user clicks another html on my page. I tried using jQuery to select the circle of legends "Stream0" on the nvd3 main page ( http://nvd3.org/ ) and click on it using this snippet in the console:

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

For reasons that I hope will be immediately apparent to people more knowledgeable about javascript, nothing happens. Does this have anything to do with event delegation?

http://nvd3.org/

+4
source share
2 answers

you can try the following:

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

He will add your own method to the legend; it works for a pie chart, not sure if it works for a line chart;

+7
source

Perhaps there is some help. Two diagrams, one pie, one stack, but only showing the legends on the pie. The data is not identical, but the legends ... Want to update both clicks on the pie legends.

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

Note: using ".pie" extends the event (library) stateChange (does not overwrite it). Another diagram, stacked, should be in scope. Note that there is a changeState and stateChange event, it is best to look at the un-minified nvd3 js file ..

+1
source

Source: https://habr.com/ru/post/1499524/


All Articles