javascript - Creating Bars in D3js -


i following example of book, interactive data visualization web deals using rect create bar. issue facing origin of each bar , it's sliding down. code given below:

<!doctype html> <meta charset="utf-8"> <html>   <head>     <title>census</title>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <script type="text/javascript" src="../d3/d3.min.js"></script>   </head>   <body>   <style>       div.bar {         display: inline-block;         width: 20px;         height: 75px; /* we'll override height later */         background-color: teal;         margin-right: 5px;         margin-bottom: 320px;         }         rect{             margin-right: 5px; }   </style>       <script>           //var dataset = [ 5,10,15];           var dataset = [ 5, 10, 13, 19, 21, 25, 22, 18, 15, 13, 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ];           /*d3.select("body").selectall("div")             .data(dataset)             .enter()             .append("div")             .style("height", function(d) {                     return d*5 + "px";                 })             .attr("class", "bar");             */               var w = 500;              var h = 100;              var barpadding = 4;              var svg = d3.select("body")                 .append("svg")                 .attr("width", 520)                 .attr("height", 300)                 .style("border", "1px solid black");                  svg.selectall("rect")                     .data(dataset)                     .enter()                     .append("rect")                     .attr("x", function(d, i) {                         return * 21; //bar width of 20 plus 1 padding                     })                     .attr("y", function(d) {                         return h - d; //height minus data value                     })                     .attr("width",20)                     .attr("height", function(d) {                         return d; //this cause issue guess                     });       </script>   </body> </html> 

the code generate following output:

enter image description here


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -