0

I am trying to do an drill-down on bar graph using NVD3.js library. Chart has been made successfully. now I want to call an Json API by clicking on a particular bar so that new chart can be generated as per the parameter.

nv.addGraph(function() {
    var chart = nv.models.discreteBarChart()
        .x(function(d) { return d.label })
        .y(function(d) { return d.value })
        .showValues(true)
        .duration(1000)
        .showLegend(true)
        ;
     d3.select('#chart1 svg')
     .datum(data)
     .transition().duration(500)
     .call(chart);

            chart.discretebar.dispatch.on("elementClick", function(e) {
    alert("You've clicked " + e.data.label);
  });


        d3.select('#chart1 svg').datum(historicalBarChart).call(chart);


        nv.utils.windowResize(chart.update);
        return chart;
    });

I get the alert with the label value of the bar on which i clicked. Now I want to call an Json API instead of alert.

Kindly help

Thanks

  • Simple replace this alert line with an AJAX call. [Here](http://stackoverflow.com/questions/9984665/external-api-get-request-using-jquery) is an example to do it jQuery – shabeer90 May 11 '17 at 12:04
  • Is there any option in to call json api in nvd3 charts? – Nishant Gupta May 11 '17 at 17:46

1 Answers1

-1

Refer to http://learnjsdata.com/read_data.html

d3.json("/data/employees.json", function(data) {
  console.log(data[0]);
});
jeznag
  • 4,183
  • 7
  • 35
  • 53