javascript - Multiple ellipses in D3 not visible with no error -


a simple program multiple ellipse have written. program shows no error no ellipse being seen. though tried add multiple random colors it. think there slight mistake somewhere. can out?

snippet:

<html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>  <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js"></script>  <script>  $(document).ready(function(){      //our basic data       var customdata = [         { "x": 30, "y": 30, "width": 20, "height" : 10 },         { "x": 70, "y": 70, "width": 20, "height" : 20},         { "x": 110, "y": 100, "width": 20, "height" : 30}      ];      //make svg container     var mysvg = d3.select("svg");      //create ellipses skeleton data       var ellipses = mysvg.selectall("ellipse")             .data(customdata)             .enter()             .append("ellipse");      //draw rectangle     ellipses.append("ellipse")         .attr("cx", function (d) { return d.x; })         .attr("cy", function (d) { return d.y; })         .attr("rx", function (d) { return d.width; })         .attr("ry", function(d) { return d.height; })         .attr("fill",function() { return "hsl(" + math.random() * 360 + ",100%,50%)"; });  });  </script>    </head> <body>     <svg width="500px" height="500px"></svg> </body> </html> 

you appending ellipse elements twice. here working snippet.

var customdata = [{    "x": 30,    "y": 30,    "width": 20,    "height": 10  }, {    "x": 70,    "y": 70,    "width": 20,    "height": 20  }, {    "x": 110,    "y": 100,    "width": 20,    "height": 30  }];    //make svg container  var mysvg = d3.select("svg");    //create ellipses skeleton data    var ellipses = mysvg.selectall("ellipse")    .data(customdata)    .enter()    .append("ellipse");    // removed second append here    //draw rectangle  ellipses.attr("cx", function(d) {      return d.x;    })    .attr("cy", function(d) {      return d.y;    })    .attr("rx", function(d) {      return d.width;    })    .attr("ry", function(d) {      return d.height;    })    .attr("fill", function() {      return "hsl(" + math.random() * 360 + ",100%,50%)";    });
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>  <svg width="500px" height="500px"></svg>


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -