I am using the following code to set the label in y-axis for discrete bar chart in nvd3 but it doesn't show the label for y-axis. BTW, x-axis label works fine.
chart.yAxis.axisLabel('Students (in %)');
One thing to watch out for is that if the chart.margin
value is too small on the left, there won't be enough room for the label to display. You can either adjust the chart.margin
value or move the y-axis label closer to the chart by adjusting the axisLabelDistance
option:
chart.yAxis
.axisLabel('Students (in %)')
.axisLabelDistance(40);
The following works:
nv.addGraph(function() {
var chart = nv.models.discreteBarChart()
.x(function(d) { return d.label })
.y(function(d) { return d.value })
.staggerLabels(true)
.tooltips(false)
.showValues(true)
chart.yAxis.axisLabel("Students (in %)")
d3.select('#chart svg')
.datum(data)
.transition().duration(500)
.call(chart);
nv.utils.windowResize(chart.update);
return chart;
});
You might have a typo somewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With