A bucket, also called a bin, groups data points whose values fall within a range. Buckets turn individual values into a distribution: you can see how many values occur in each part of an axis. They are generally equal in width, not necessarily equal in the number of points they contain. section 6.1 section 6.6
Salary brackets as buckets
A survey response of $20,000–$39,999 identifies a salary range, not an exact salary. That bracket is a bucket: it tells you where the value belongs without revealing the value itself. To practice drawing charts, the salary project generates a random value inside each reported bracket. Those generated values are illustrative, not observed salaries. section 6.1
In D3, `d3.bin()` prepares buckets for drawing. Point its value accessor at the field you want to group, then pass in the data: `const bins = d3.bin().value(d => d.salary)(data);`. The result is an array of bins. Each bin contains its data points; `x0` and `x1` give its lower and upper boundaries, and `length` gives its point count. section 6.1
Figure 6.3 In the multidimensional array returned by the bin generator, each bin is an array containing data points. In this figure, the data points, consisting of JavaScript objects, are represented by {...} for conciseness. A bin’s lower and upper limits are accessible under the keys x0 and x1.
Inspect the nested array to see the difference between a bin’s contained data points and its `x0` and `x1` boundaries. section 6.1
Once you have bins, connect each count to a visible mark:
- For a histogram, bind bins to SVG rectangles. Position each rectangle using `x0`, set its width from `x1 - x0` through the horizontal scale, and set its height from `length` through the vertical scale. Taller rectangles indicate more values in that range. section 6.2
- For violin plots, bin salaries separately for each category. Use each bin’s count to determine the plot’s width at that salary range, then draw a curved area through those widths. section 6.5
- For an interactive histogram, filter the data and run it through the bin generator again. Bind the updated bins to the rectangles so their heights reflect the selected group. section 7.2.3








