javascript - D3 : Retrieve data from SVG -


is possible retrieve data svg via d3?

i have following scenario: on page resize need update widths of svg generated on server via d3 . example x-axis. client side d3 library has no knowledge of svg. noticed each dom object there __ chart__ object. there way can access range , domain example , update them accordingly?

when create svg on server , transfer client, actual svg dom gets transferred, not javascript objects or properties (such d3 __data__ property) used in creating it.

so in order attach data svg elements gets passed file, need create attribute of element contains data. can select element client side , parse data attribute.

example:

/*** server side ***/ /* if `bars` d3 selection of rectangles in bar graph */ bars.attr("data-name", function(d){return d.name;})     .attr("data-value", function(d) {return d.value;});  /*** client side ***/ var bars = d3.selectall("rect.bar")              .datum(function(){                 return {                   name: this.getattribute("data-name"),                   value: this.getattribute("data-value")                 }              })              .on("click", function(d,i){                  /* data */              }); 

that works if data in question few numbers or names want use in tooltips or similar interaction. doesn't work complex object chart function. if you're need redraw/resize chart client-side, don't see performance benefit in trying draw graphs server-side.

you can create server scripts parse data ready-to-use format, maybe run d3 layout functions create ready-to-draw json array. draw graph client-side.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -