Question

I have a number of nvd3 charts on a page, and I store some useful information in the chart's id attribute (basically a rowkey that I used to populate the data).

What I want to do is fetch additional data when the user clicks a point on the graph.

The problem is, with many graphs on the page, when the user clicks (I have registered for lines.dispatch.on('elementClick')), I need to somehow know which graph I am on so I have the information I need to make the subsequent query.

Is there some way to grab the containing chart information when the user clicks on a point? Or knowing the chart's ID?

Was it helpful?

Solution

If you have jquery on your page, then you can use jquery.closest to look for the parent chart element and extract its ID:

.on('elementClick', function (d, i) {
    var chartId = $(this).closest('svg').attr('id');
    // ...
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top