Reputation: 3673
I am using D3JS to create a graph. I would like to retrieve the size of the graph to use elsewhere in my code in javascript. When inspecting the element in firebug and going to the layout tab, it shows the dimensions in pixels which is what I am trying to grab programatically. However, trying to do something like grab the G by typing $('g').height() returns 0. Is there a special way I am supposed to grab the element to get its full rendered height and width?
Upvotes: 4
Views: 3104
Reputation: 123995
The SVG way is to call element.getBBox(). That will give you an object with width and height properties.
Upvotes: 4