freeCodeCamp/guide/english/certifications/data-visualization/data-visualization-with-d3/set-a-domain-and-a-range-on.../index.md

32 lines
612 B
Markdown
Raw Normal View History

2018-10-12 19:37:13 +00:00
---
title: Set a Domain and a Range on a Scale
---
## Set a Domain and a Range on a Scale
2018-11-06 22:29:28 +00:00
### Hint 1
2018-10-12 19:37:13 +00:00
2018-11-06 22:29:28 +00:00
Use the `.domain()` and `.range()` functions.
2018-10-12 19:37:13 +00:00
2018-11-06 22:29:28 +00:00
### 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>
```