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

More Query from same tag