2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Add a Tooltip to a D3 Element
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Add a Tooltip to a D3 Element
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2018-10-17 22:05:20 +05:30
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2018-10-17 22:05:20 +05:30
|
|
|
Use the ` .append() ` method.
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2018-10-17 22:05:20 +05:30
|
|
|
### Hint 2
|
|
|
|
|
|
|
|
Use the ` .text() ` method.
|
|
|
|
|
|
|
|
### Hint 3
|
|
|
|
|
|
|
|
Chain the ` .append() ` and ` .text() ` methods.
|
|
|
|
|
|
|
|
### Hint 4
|
|
|
|
|
|
|
|
Use a callback function in the ` .text() ` method.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2018-10-17 22:05:20 +05:30
|
|
|
|
|
|
|
Chain the following lines of code with your ` svg.selectAll("rect") ` method.
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
.append("title")
|
|
|
|
.text(d=>d);
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|