.create("div"): will create a divHTMLElement.attr: will set an attribute.style: will set a style- It's important to note that you don't have to
createan element, you can useselectto select an element you wantattr/styleto apply to as well using normal selectors.
div: you're gonna want to run the d3 methods on a D3 "selection" (aka a sparkling HTMLElement).selectAll: Define the initial (empty) selection for the bars..data: Bind this selection to the array of data.join("div")sets the element for each bar.style: set the style of the bar,style("width", (d) => `${x(d)}px`)contains a callback wheredis the data item of the array we're currently on for the bar, and returns a pixel value. See 1.3 to understand whatx()does..text((d) => d)inserts text into each bar.
If you want to make the bars scale to a min/max value, use this. domain will take a min and max value for what you want to operate within the: range which will take in an arbitrary min and a max; scaleLinear() will scale the values of domain to be within range.