.DS_Store
# use-d3-v3-to-build-interactive-charts-with-javascript
body {
padding-top: 50px;
padding-left: 100px;
}
#chartArea {
width: 400px;
height: 300px;
background-color: #CCC;
}
.bar {
display: inline-block;
width: 20px;
/* Gets overriden by D3-assigned height below */
margin-right: 2px;
fill: teal;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/lodash@4.17.4/lodash.js"></script>
<meta charset="utf-8">
<link rel="stylesheet" href="./app.css">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.js"></script>
</head>
<body>
<div id="chartArea"></div>
<script src="script.js"></script>
</body>
</html>
var dataset = _.map(_.range(15), function (i ) {
return Math.random() * 5000;
});
var w = 400, h = 300;
var svg = d3.select('#chartArea').append('svg')
.attr('width', w)
.attr('height', h);
var yScale = d3.scale.linear()
.domain([0, d3.max(dataset) * 1.1])
.range([0, h]);
var multiplier = 5;
svg.selectAll('rect')
.data(dataset)
.enter()
.append('rect')
.attr('class', 'bar')
.attr('x', function (d, i) {
return i * 22;
})
.attr('y', function (d) {
return h - yScale(d);
})
.attr('width', 20)
.attr('height', function (d) {
return yScale(d);
});