UPDATE:
I solved this issue rather crudely. So I’m going to go through it again to resolve the ‘padding’ issue:
const xScale = d3.scaleTime()
.domain(
[
new Date(d3.min(data, (d) => d[0])),
new Date(d3.max(data, (d) => d[0]))
]
)
**.range([padding, 788])**
My Bar Chart data is as it should be.
The data bars are displaying correctly but not matching the ticks on the xAxis.
So the x-axis ticks are going beyond the bars.
Does this mean my d3.scaleTime() is correct and there is something wrong the ticks?
const xScale = d3.scaleTime()
.domain(
[
new Date(d3.min(data, (d) => d[0])),
new Date(d3.max(data, (d) => d[0]))
]
)
.range([padding, w])
svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("class", "bar")
.attr("width", w / xScale(data.length))
.attr("height", d => h - yScale(d[1]))
.attr("data-date", d => d[0])
.attr("data-gdp", d => d[1])
.attr("x", (d, i) => (i * w / xScale(data.length)) + padding)
.attr("y", (d) => yScale(d[1]) - padding);
svg.append("g")
.attr("transform", "translate(0," + (h - padding) + ")")
.attr("id", "x-axis")
.attr("class", "tick")
.call(xAxis)