score:2

Accepted answer

i've modified your example slightly http://jsfiddle.net/fjuak9bo/9/ which i believe provides the solution you want.

the important part is to set your domain on the yscale appropriately. here i'm detecting if all values are +ve or -ve, and setting the domain between -100-0 or 0-100.

yscale.domain([-100, 100])
          .range([height - margin.top - margin.bottom, 0])
          .nice();         

    if(min > 0) { 
        // all positive
        yscale.domain([0, 100]);
    } else if(max < 0) {
        // all negative
        yscale.domain([-100, 0]);   
    }

you could if you needed extend the min/max on the domain if you're values exceed +- 100%.


Related Query