It sounds like in your case an easier course of action would be to get the container of the graph (i.e. the SVG) and calculate its center point. Assuming that the margins of the graph you're drawing are not too big and/or unbalanced, the behaviour would be very similar to computing the centroid of the graph, but much easier to achieve.
The code would look something like this.
var centerx = svg.getBBox().x + svg.getBBox().width/2,
centery = svg.getBBox().y + svg.getBBox().height/2;