Hi, everyone! I got stuck with this simple D3 project . Please, help.
I am using a hard-coded dataset to draw a bar chart, and everything works fine. But there are no text labels on my chart. There are No errors in the console, no text - tags at all in the final html.
Here is my codepen for the project:
Bar chart
**let svg = d3.select(‘section’)
.append(“svg”)
.attr(“width”, width)
.attr(“height”, height);
const xAxis = d3.axisBottom(xScale);
svg.append(“g”)
.attr(“transform”, “translate(0,” + (height - padding) + “)”)
.call(xAxis);
const yAxis = d3.axisLeft(yScale);
svg.append(“g”)
.attr(“transform”, “translate(” + padding + “, 0)”)
.call(yAxis);
svg.selectAll(‘rect’)
.data(dataset)
.enter()
.append(‘rect’)
.attr(“x”, (d, i) => xScale(i * padding))
.attr(“y”, (d, i) =>height - yScale( d[1]) - padding)
.attr(“width”, 25)
.attr(“height”, (d, i) => yScale(d[1]))
.attr(“fill”, “navy”);
svg.selectAll(“text”)
.data(dataset)
.enter()
.append(“text”)
.text((d) => d[0])
.attr(“x”, (d, i) => xScale(i * padding))
.attr(“y”, (d, i) =>400)
.attr(‘fill’, ‘black’);**
Chrome latest
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36
.
Challenge: Visualize Data with a Bar Chart
Link to the challenge: