From e6fef5ff342f63438ddcca3ec0d3262f5212c8f6 Mon Sep 17 00:00:00 2001 From: The Coding Aviator <34807532+thecodingaviator@users.noreply.github.com> Date: Thu, 16 May 2019 21:34:08 +0530 Subject: [PATCH] Added solution to D3 use dynamic scales challenge (#34241) * Update index.md * Update index.md * Update spacing * Update index.md --- .../use-dynamic-scales/index.md | 67 ++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/guide/english/certifications/data-visualization/data-visualization-with-d3/use-dynamic-scales/index.md b/guide/english/certifications/data-visualization/data-visualization-with-d3/use-dynamic-scales/index.md index 20c2b5fd35..091652f0a9 100644 --- a/guide/english/certifications/data-visualization/data-visualization-with-d3/use-dynamic-scales/index.md +++ b/guide/english/certifications/data-visualization/data-visualization-with-d3/use-dynamic-scales/index.md @@ -3,8 +3,69 @@ title: Use Dynamic Scales --- ## Use Dynamic Scales -This is a stub. Help our community expand it. +### Hint 1 -This quick style guide will help ensure your pull request gets accepted. +Use the `.domain()` and `.range()` functions. - +### Hint 2 + +Use a callback function on the `.domain()` function. + +### Hint 3 + +Both the `.domain()` and `.range()` functions accept an array or two elements. + +### Hint 4 + +Subtract padding from height to get SVG height including padding. + +### Solution + +To solve the solution by including all the hints, set the `yScale` variable to: + +```js +const yScale = d3.scaleLinear() + .domain([0, d3.max(dataset, (d) => d[1])]) + .range([h - padding, padding]); +``` + +The full solution now looks like: + +```html + + + +```