d3.scalePoint() creates a point scale for placing discrete values across a continuous range. Unlike a band scale, it has zero bandwidth: each domain value maps to a position rather than an interval. section 6.4.3 section 6.6
Configure a point scale by defining its categories, available space, and edge spacing:
- Pass a discrete array to domain(), such as ["Female", "Male"] or the role identifiers from a dataset. section 6.4.3 section 6.5
- Set range([0, innerWidth]) to distribute the points across the chart’s horizontal space. section 6.4.3 section 6.5
- Use padding() with a factor between 0 and 1 to add blank space at both ends; the factor multiplies the scale step. section 6.4.3
Place categories on a chart
const genders = ["Female", "Male"]; const xScale = d3.scalePoint() .domain(genders) .range([0, innerWidth]) .padding(0.5); const bottomAxis = d3.axisBottom(xScale) .tickSizeOuter(0); innerChart.append("g") .attr("transform", `translate(0, ${innerHeight})`) .call(bottomAxis);
Use the returned scale as a function: xScale(category) supplies the category’s horizontal position. In violin plots, roles occupy these positions while separate linear scales handle salary values and violin widths. section 6.5
