Built with blockbuilder.org
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
#chart {
margin: 1em 3em;
}
.note {
margin-top: 1em;
font-size: 1.2em;
background-color: #D8D8D8;
}
.bar {
background-color: blue;
height: 20px;
margin-top: 2px;
}
</style>
</head>
<body>
<div class="note">
<p>You need 4 properties to create a SVG rect: x, y, width, height</p>
<p>More at <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/rect">MDN Docs</a></p>
</div>
<svg id="chart">
<rect/>
<rect/>
<rect/>
<rect/>
<rect/>
</svg>
<script>
var rectWidth = 50;
var chartHeight = 400;
var chartWidth = 700;
var data = [200, 60, 100, 80, 10];
var svg = d3.select('#chart')
.attr('height', chartHeight)
.attr('width', chartWidth);
svg.selectAll('rect')
.data(data)
.attr('x', function(d, i){
return i * rectWidth;
})
.attr('y', function(d){
return chartHeight - d;
})
.attr('width', rectWidth)
.attr('height', function(d){
return d;
})
.attr('fill', 'blue')
.attr('stroke', '#FF00FF')
.attr('stroke-width', '2');
</script>
</body>
https://d3js.org/d3.v4.min.js