Update index.md (#34231)
This commit is contained in:
committed by
Paul Gamble
parent
dac5f58205
commit
069d17dc01
@ -3,8 +3,29 @@ title: Set a Domain and a Range on a Scale
|
|||||||
---
|
---
|
||||||
## Set a Domain and a Range on a Scale
|
## Set a Domain and a Range on a Scale
|
||||||
|
|
||||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/data-visualization/data-visualization-with-d3/set-a-domain-and-a-range-on-a-scale/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
### Hint 1
|
||||||
|
|
||||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
Use the `.domain()` and `.range()` functions.
|
||||||
|
|
||||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
### Hint 2
|
||||||
|
|
||||||
|
Both the the `.domain()` and `.range()` functions accept an array of two elements.
|
||||||
|
|
||||||
|
## Spoiler Alert | Solution Ahead
|
||||||
|
### Solution
|
||||||
|
|
||||||
|
The `domain` and `range` functions can be chained, and the following is the solution:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
const scale = d3.scaleLinear()
|
||||||
|
.domain([250, 500])
|
||||||
|
.range([10, 150]);
|
||||||
|
const output = scale(50);
|
||||||
|
d3.select("body")
|
||||||
|
.append("h2")
|
||||||
|
.text(output);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
```
|
||||||
|
Reference in New Issue
Block a user