Modifying an SVG in HTML using d3

e7h3r

this is my first post so I'll try to make sure I'm following appropriate posting etiquette.

I have no experience whatsoever with html, d3, or javascript. I do however have some exposure to xml and svg. I'm trying to work through this tutorial: [http://bost.ocks.org/mike/circles/]. I spent several hours yesterday fruitlessly attempting to complete the first step, which is to change the color and radius of the three circles using d3.selectAll(). I've read through several posts on here and looked at other tutorials but I cannot for the life of me make the circles blue. Unfortunately the tutorial never shows the entirety of their code. I've been able to display the three black circles (original svg) in my browser but can't seem to get d3 to select them and carry out the changes. I'm not even sure if the xml is embedded within the html or if it is external and read in somehow.

Could someone post the html you would use to do this? Any assistance would be greatly appreciated.

Here is the xml corresponding to the circles:

<svg width="720" height="120">
<circle cx="40" cy="60" r="10"></circle>
 <circle cx="80" cy="60" r="10"></circle>
  <circle cx="120" cy="60" r="10"></circle>
</svg>

And here is the code to make the changes:

var circle = d3.selectAll("circle");
circle.style("fill", "steelblue");
circle.attr("r", 30);
Mark

Your code is correct. I'm guessing you aren't putting it together correctly. Here's the shortest example:

<!DOCTYPE html>
<html>

  <head>
    <script data-require="[email protected]" data-semver="3.5.3" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.js"></script>
  </head>

  <body>
    <svg width="720" height="120">
      <circle cx="40" cy="60" r="10"></circle>
      <circle cx="80" cy="60" r="10"></circle>
      <circle cx="120" cy="60" r="10"></circle>
    </svg>
    <script>
      var circle = d3.selectAll("circle");
      circle.style("fill", "steelblue");
      circle.attr("r", 30);
    </script>
  </body>

</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Background image to SVG choropleth map using D3

From Dev

How to update all data representing an SVG line using d3?

From Dev

How to generate svg client-side with d3 without attaching it to the DOM (using with React.js)

From Dev

Is it possible to edit an svg:image styles in the browser? (using D3)

From Dev

How to render end ticks always using d3 svg axis

From Dev

Modifying HTML using java

From Dev

Using D3 to fill an svg with a background image

From Dev

Returning d3 SVG HTML in PhantomJS

From Dev

Modifying svg files using javascript

From Dev

D3/SVG: How to resize a d3.svg.axis with time scale by modifying range?

From Dev

d3 - rendering an html table on top of an svg element

From Dev

svg rendering order of lines and shapes when using d3

From Dev

d3 modifying column names

From Dev

Selecting SVG items using D3 DataMaps?

From Dev

Zoom to bounding box of path on externally loaded svg using D3

From Dev

Using angular function binding inside .html() in d3

From Dev

Using SVG attributes in variables in d3

From Dev

Using Rickshaw/D3 in Node.js,for server side, raw svg accessible?

From Dev

How to generate svg client-side with d3 without attaching it to the DOM (using with React.js)

From Dev

Is it possible to edit an svg:image styles in the browser? (using D3)

From Dev

Using SVG Images in HTML?

From Dev

angular custom charting svg or canvas or d3 or html?

From Dev

Creating array from html to display using D3 Wordcloud

From Dev

Modifying an SVG in HTML using d3

From Dev

How to change properties of elements in a SVG when I mouseover an element of a second SVG using D3

From Dev

selection in d3 svg

From Dev

SVG filter using d3 js not working in IE

From Dev

"Property does not exist on type {}" error when using anonymous function with D3 SVG Symbol

From Dev

CSV to HTML table using d3 and an external javascript file

Related Related

  1. 1

    Background image to SVG choropleth map using D3

  2. 2

    How to update all data representing an SVG line using d3?

  3. 3

    How to generate svg client-side with d3 without attaching it to the DOM (using with React.js)

  4. 4

    Is it possible to edit an svg:image styles in the browser? (using D3)

  5. 5

    How to render end ticks always using d3 svg axis

  6. 6

    Modifying HTML using java

  7. 7

    Using D3 to fill an svg with a background image

  8. 8

    Returning d3 SVG HTML in PhantomJS

  9. 9

    Modifying svg files using javascript

  10. 10

    D3/SVG: How to resize a d3.svg.axis with time scale by modifying range?

  11. 11

    d3 - rendering an html table on top of an svg element

  12. 12

    svg rendering order of lines and shapes when using d3

  13. 13

    d3 modifying column names

  14. 14

    Selecting SVG items using D3 DataMaps?

  15. 15

    Zoom to bounding box of path on externally loaded svg using D3

  16. 16

    Using angular function binding inside .html() in d3

  17. 17

    Using SVG attributes in variables in d3

  18. 18

    Using Rickshaw/D3 in Node.js,for server side, raw svg accessible?

  19. 19

    How to generate svg client-side with d3 without attaching it to the DOM (using with React.js)

  20. 20

    Is it possible to edit an svg:image styles in the browser? (using D3)

  21. 21

    Using SVG Images in HTML?

  22. 22

    angular custom charting svg or canvas or d3 or html?

  23. 23

    Creating array from html to display using D3 Wordcloud

  24. 24

    Modifying an SVG in HTML using d3

  25. 25

    How to change properties of elements in a SVG when I mouseover an element of a second SVG using D3

  26. 26

    selection in d3 svg

  27. 27

    SVG filter using d3 js not working in IE

  28. 28

    "Property does not exist on type {}" error when using anonymous function with D3 SVG Symbol

  29. 29

    CSV to HTML table using d3 and an external javascript file

HotTag

Archive