I'm new to d3.js and I'm creating a simple horizontal bar chart with two bars. I want to put text labels on the two bars. The code below looks correct according to my research, but no text shows on the screen. From the dev console, it looks like the text elements are not being added.
Here's the javascript code:
var dataArray = [23, 13];
var svg = d3.select("svg.d3svg")
.attr("height", "20%")
.attr("width", "100%")
.selectAll("rect")
.data(dataArray)
.enter().append("rect")
.attr("height", "7")
.attr("width", "250")
.attr("y", function(d, i) {return (i * 40) + 50 })
.attr("x", "0")
.attr("class", "d3bar");
svg.selectAll("text")
.data(dataArray)
.enter().append("text")
.attr("class", "text-svg")
.text(function(d) {return d})
.attr("x", "0")
.attr("y", function(d, i) {return (i * 40) + 50});
The text-svg class contains only:
.text-svg {
fill: white;
font-family: sans-serif;
}
This correctly code targets the svg element on the html page because the bars are placed where I want them, but I haven't been able to get the text to show.
Thanks for any help.