Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nvd3 discreteBarChart y axis label

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 %)');
like image 748
Ramesh Avatar asked Jun 25 '13 04:06

Ramesh


2 Answers

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);
like image 104
cschroed Avatar answered Oct 13 '22 00:10

cschroed


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.

like image 45
Christopher Chiche Avatar answered Oct 12 '22 22:10

Christopher Chiche