Is there any easy way to assign JSON data to svg element using Javascript? -
i new svg, , trying create simple graph using it. don't know how assign json data draw rectangle in svg dynamically using 'for loop'.help me 1 loop , assigning each value draw rectangle want append svg element.
<script src="http://d3js.org/d3.v3.min.js"></script> <script> window.onload = function(){ var data = [ { "srno" : 1 , "status" : "production" , "duration" : 30, "color" : "#00ff00", }, { "srno" : 2 , "status" : "idle" , "duration" : 5 , "color" : "#ff0000"}]; //make svg container var svgcontainer = d3.select("body").append("svg") .attr("width", 720) .attr("height", 50); //draw rectangle var rectangle = svgcontainer.append("rect") .attr("x", 0) .attr("y", 0) .attr("width", machines [1].duration) .attr("height", 50) .attr("fill","green");//here want color json object //and want duration width property, //status tooltip , not working </script>
here article can learn on how that:
http://tympanus.net/codrops/2013/11/05/animated-svg-icons-with-snap-svg/
you can download source files, within "js" directory find json file using svg data.
you might consider use snap.svg, lot:
hope helps you!
Comments
Post a Comment