-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path3.html
66 lines (66 loc) · 2.43 KB
/
3.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<html>
<head>
<title>D3 tutorial</title>
<!--[if lte IE 8]><script src="r2d3.min.js" charset="utf-8"></script><![endif]-->
<!--[if gte IE 9]><!-->
<script src="http://d3js.org/d3.v3.min.js"></script>
<!--<![endif]-->
<script src="https://google-code-prettify.googlecode.com/svn/loader/prettify.js"></script>
<link href="https://google-code-prettify.googlecode.com/svn/loader/prettify.css" type="text/css" rel="stylesheet" />
</head>
<h3>Basic SVG shapes</h3>
<a href="index.html">Back to table of contents</a>
<body onload="prettyPrint()">
<pre class="prettyprint">
// append svg object to the dom body and assign to variable canvas
var canvas = d3.select("body")
.append("svg")
// specify width and height
.attr("width", 500)
.attr("height", 500);
// create a circle and assign attributes.
var circle = canvas.append("circle")
.attr("cx", 250)
.attr("cy", 250)
.attr("r", 50)
.attr("fill", "red");
// create a rectangle and assign attributes.
var rect = canvas.append("rect")
.attr("width", 250)
.attr("height", 250);
// create a line and assign attributes.
var line = canvas.append("line")
// x1 first horizontal position of the line
.attr("x1", 0)
// y1 first vertical position of the line
.attr("y1", 100)
// second point where the line goes to
.attr("x2", 400)
.attr("y2", 400)
.attr("stroke", "green")
.attr("stroke-width", 10);
</pre>
<script>
var canvas = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 500);
var circle = canvas.append("circle")
.attr("cx", 250)
.attr("cy", 250)
.attr("r", 50)
.attr("fill", "red");
var rect = canvas.append("rect")
.attr("width", 250)
.attr("height", 250);
var line = canvas.append("line")
.attr("x1", 0)
.attr("y1", 100)
.attr("x2", 400)
.attr("y2", 400)
.attr("stroke", "green")
.attr("stroke-width", 10);
</script>
</body>
</html>