score:1

Accepted answer

there are several ways for positioning the y axis in the centre, this is one of them:

find the maximum absolute value in your x scale...

var maxvalue = (math.abs(d3.min(data, function(d) {
        return d.interactions; 
    })) > math.abs(d3.max(data, function(d) { 
        return d.interactions; 
    }))) ? math.abs(d3.min(data, function(d) {
        return d.interactions; 
    })) : math.abs(d3.max(data, function(d) {
        return d.interactions; 
    }));

and use this value to set a symmetrical domain:

x.domain([maxvalue*-1, maxvalue]);

this is the fiddle: https://jsfiddle.net/b1xhyo6c/1/


Related Query

More Query from same tag