Built with blockbuilder.org
Credit goes to Ben Clinkinbeard's "Learn D3 in 5 Days" course
This is the finished product of the course.
And here are the notes I took throughout the course:
d3.select('#foo').selectAll('p')
function(d, i, nodes){
}
this
is bound to actual DOM element (not true if you use arrow function)selection.on('type', listener)
invert
methodconst decimalToPercent = d3.scaleLinear()
.domain([0, 1])
.range([0, 100])
decimalToPercent.invert(50) // 0.5
clamp
methodconst percentToDecimal = d3.scaleLinear()
.domain([0, 100])
.range([0, 1])
.clamp(true)
percentToDecimal(-10) // 0
percentToDecimal(150) // 1
percentToDecimal(200) // 1
bandScale
is a good way to calculate width (or height in this case) of bars
selection.call
is used to invoke a method and pass the selection to and then return the selectionforked from mell0kat's block: Animated Bar Chart
xxxxxxxxxx
<html>
<head>
<title>d3 in 5 Days - Aniamated Bar Chart</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<div id="chart">
</div>
<button onclick="render('math')">Math</button>
<button onclick="render('science')">Science</button>
<input type="text" id="userName" />
<button id="addUser">Add User</button>
<script src="index.js"></script>
</body>
<style type="text/css">
#chart {
padding: 10px 10px 20px 50px;
position: relative;
margin-top: 20px;
}
.bar {
background-color: teal;
height: 20px;
margin-top: 2px;
}
</style>
</html>
https://d3js.org/d3.v5.min.js