I have this d3 project where I created bar chart. I have several bars and I want data to display once I hover over the specific bar. However, for some reason it doesn't display the content despite the data and css being present. I created rects elements as bars and and a div element with the class of tooltip that includes the data. Please help.
Here is my code:
chart.selectAll("rect")
.data(json.data)
.enter()
.append("rect")
.attr("x", (d) => xScale(parseDate(formatDate(d[0]))))
.attr("y", (d) => yScale(d[1]))
.attr("height", (d) => height - yScale(d[1]))
.attr("width", xScale.bandwidth())
.attr("class", "rect-col")
.append("div")
.attr("class", "tooltip")
.text((d) => d[0] + d[1])
.on("mouseenter", function (d, i) {
//d3.select(this).style("fill", "#EE9A2F");
d3.select(this).style("visibility", "visible");
})
.on("mouseleave", function (d, i) {
//d3.select(this).style("fill", "#EECF10");
d3.select(this).style("visibility", "visible");
});
my css:
.tooltip {
text-align: center;
width: 60px;
height: 28px;
padding: 2px;
font: 12px sans-serif;
background: green;
border: 0px;
border-radius: 8px;
pointer-events: none;
color: red;
visibility: hidden;
}
link to my codepen codepen