Add a Tooltip to a D3 Element

Tell us what’s happening:
I’m trying to call the text() method with a callback function so the text displays the data value…

Your code so far

  .bar:hover {
    fill: brown;
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
    const w = 500;
    const h = 100;
    const svg ="body")
                  .attr("width", w)
                  .attr("height", h);
       .attr("x", (d, i) => i * 30)
       .attr("y", (d, i) => h - 3 * d)
       .attr("width", 25)
       .attr("height", (d, i) => d * 3)
       .attr("fill", "navy")
       .attr("class", "bar")
       // Add your code below this line
       // Add your code above this line
       .text((d) => d)
       .attr("x", (d, i) => i * 30)
       .attr("y", (d, i) => h - (d * 3 + 3))   

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:

1 Like


Here you’re supposed to assign the value but you’re assigning a string^^
You might want to look at the code below in the challenge, where it assign the text to the labels - it’s the exact same thing^^

I’ll blur the solution here but try to solve it by yourself ( once understood will be an easy task):

.text( d => d)
1 Like