How to get label name on click of bar. I'm using NVD3 Graph. this is the reference link of NVD3 chart chart link: link
This way I'm bind the click event of bar chart example link: link
var newarraydata = [];
d3.json('http://developers.nncinfotech.com/betafishfront-aj/guser_data/591574b7e4365e0004356c3f_product.json', function(data) {
nv.addGraph(function() {
///console.log(data);
var chart = nv.models.multiBarHorizontalChart()
.x(function(d) { newarraydata[d.label] = d.ProductName; return d.label })
.y(function(d) { return d.value })
.margin({top: 10, right: 45, bottom: 25, left: 70})
.showValues(true) //Show bar value next to each bar.
.tooltips(true) //Show tooltips on hover.
.tooltipContent(function(d, y, e, graph) {
return '<div style="position: relative;text-align: left;"><h5 style="text-align: center;padding: 5px;">Products</h5> <hr style="width: 90%;margin: 0 auto;text-align: center;"><p style="text-align: left;"> ' + newarraydata[y].replace(/,/g, ", <br>") + '</p></div>'
})
.transitionDuration(350)
.showControls(false); //Allow user to switch between "Grouped" and "Stacked" mode.
chart.valueFormat(d3.format('d'));
d3.select('#modal_product_chart svg')
.datum(data)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
},function(){
d3.selectAll(".nv-bar.positive").on('click',
function(){
//console.log($(this));
//here I want that bar label name
});
});
});
<script type="text/javascript" src="/js/lib/dummy.js"></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/nvd3/1.1.15-beta/nv.d3.min.css">
<div id="chart1">
<svg width=600 height=500></svg>
</div>