How do I change the legend position in a NVD3 chart?

user2541050 picture user2541050 · Jul 2, 2013 · Viewed 33k times · Source

Does anyone know how to reposition the legend in a NVD3 chart relative to the graph itself?

It is on top by default, and I would like it to go on the side (better use of space within my app)

An example of what I would like to do: enter image description here

Answer

Michael picture Michael · Jul 2, 2015

As of this writing (2 jul 2015) nvd3 supports putting the legend to the right of the pie chart.

When you initialize the graph, set legendPosition to right.

Example:

nv.addGraph(function() {
    var chart = nv.models.pieChart()
      .x(function(d) { return d.label })
      .y(function(d) { return d.value })          
      .legendPosition("right");


    svg.datum(piedata).call(chart);

  return chart;
});

See http://nvd3-community.github.io/nvd3/examples/documentation.html#pieChart