From 39a9da5c1d744c71d2d284dbef16c177bf1e1bb9 Mon Sep 17 00:00:00 2001 From: The Coding Aviator <34807532+thecodingaviator@users.noreply.github.com> Date: Thu, 16 May 2019 21:34:54 +0530 Subject: [PATCH] Added solution to D3 predefined scale challenge (#34242) * Update index.md * Update index.md * spacing * Update index.md --- .../index.md | 88 ++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) diff --git a/guide/english/certifications/data-visualization/data-visualization-with-d3/use-a-pre-defined-scale-to-place-elements/index.md b/guide/english/certifications/data-visualization/data-visualization-with-d3/use-a-pre-defined-scale-to-place-elements/index.md index e19af1f8ad..2d11cf5d62 100644 --- a/guide/english/certifications/data-visualization/data-visualization-with-d3/use-a-pre-defined-scale-to-place-elements/index.md +++ b/guide/english/certifications/data-visualization/data-visualization-with-d3/use-a-pre-defined-scale-to-place-elements/index.md @@ -3,8 +3,90 @@ title: Use a Pre-Defined Scale to Place Elements --- ## Use a Pre-Defined Scale to Place Elements -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 `.attr()` function, which accepts 2 parameters. - +### Hint 2 + +Use a callback function on the `.attr()` functions. + +### Hint 3 + +The radius is set using the `r`attribute. + +### Solution + +Change the `svg.selectAll("circle")` and `svg.selectAll("text")` codeblocks to the following to complete the challenge, this has been done by incorporating all the hints from above: + +```js +svg.selectAll("circle") + .data(dataset) + .enter() + .append("circle") + .attr("cx", (d) => xScale(d[0])) + .attr("cy", (d) => yScale(d[1])) + .attr("r", 5); + +svg.selectAll("text") + .data(dataset) + .enter() + .append("text") + .text((d) => (d[0] + ", " + d[1])) + .attr("x", (d) => xScale(d[0] + 10)) + .attr("y", (d) => yScale(d[1])); +``` + +The full solution looks like: + +```html + + + +```