Search code examples
d3.jspie-chartnvd3.js

nvd3 pie outerRadius


I can not figure out how to change the radius in the diagram

nv.addGraph( function() {

    var chart = nv.models.pieChart()
            .x(function(d) { return d.label })
            .y(function(d) { return d.value })
            .width( 520)
            .height( 250)
            .donut( true)
            .showLabels( false)


    d3.select( '#stat-lang svg')
            .datum( data)
            .transition().duration(1200)
            .call( chart)

    return chart;
});

I use NVD3.


Solution

  • Based on the source code...

    var availableWidth = width - margin.left - margin.right,
        availableHeight = height - margin.top - margin.bottom,
        radius = Math.min(availableWidth, availableHeight) / 2,
        arcRadius = radius-(radius / 5), // radius
        container = d3.select(this);
    

    ...the radius is calculated based on width and height, taking the smallest of the two. So, you can only adjust the radius by feeding these dimensions to the chart, like:

    var chart = nv.models.pieChart()
        .x(function(d) { return d.label })
        .y(function(d) { return d.value })
        .showLabels(true)
        .donut(true)
        .donutRatio(0.35)
        .width(500) // width
        .height(500); // height