This repository was archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample2.html
More file actions
97 lines (92 loc) · 2.59 KB
/
Copy pathexample2.html
File metadata and controls
97 lines (92 loc) · 2.59 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<html>
<head>
<title>MAS.S70 | D3 workshop</title>
<link href="https://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet">
<style>
body {
margin: 0;
padding: 3%;
font-family: 'PT Sans', sans-serif;
}
.page {
margin: 0 auto;
max-width: 800px;
width: 90%;
}
h1 {
font-weight: normal;
text-rendering: optimizeLegibility;
}
.chart rect {
fill: rgba(3, 168, 124, 0.8);
}
.chart text {
fill: white;
font: 10px sans-serif;
text-anchor: end;
}
</style>
</head>
<body>
<div class="page">
<h1>Drawing a Bar Chart | Method Chaining</h1>
<br />
<h2> Manual bar chart </h2>
<svg class="chart" width="420" height="120">
<g transform="translate(0,0)">
<rect width="40" height="19"></rect>
<text x="37" y="9.5" dy=".35em">4</text>
</g>
<g transform="translate(0,20)">
<rect width="80" height="19"></rect>
<text x="77" y="9.5" dy=".35em">8</text>
</g>
<g transform="translate(0,40)">
<rect width="150" height="19"></rect>
<text x="147" y="9.5" dy=".35em">15</text>
</g>
<g transform="translate(0,60)">
<rect width="160" height="19"></rect>
<text x="157" y="9.5" dy=".35em">16</text>
</g>
<g transform="translate(0,80)">
<rect width="230" height="19"></rect>
<text x="227" y="9.5" dy=".35em">23</text>
</g>
<g transform="translate(0,100)">
<rect width="420" height="19"></rect>
<text x="417" y="9.5" dy=".35em">42</text>
</g>
</svg>
<p>
Ugh, the agony. Brute force is every programmer's enemy.
Laziness when it comes to mundane tasks is our greatest strength!
</p>
<br />
<h2> Simple bar chart using D3 </h2>
<p>
Let's build an identical chart using D3!
</p>
<svg id="svg2">
</svg>
<p>
What happens when we change our data and put a large number (say 100)
in our data? Our bar chart fails!!
Can we make our chart smarter by using D3 to scale our axis?
</p>
<br />
<h2> Auto scale axis based on data </h2>
<svg id="svg3">
</svg>
</div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
// Common Variables
var data = [4, 8, 15, 16, 23, 42];
var width = 420;
var barHeight = 20;
// Simple bar chart
// Chart with smart axis
</script>
</body>
</html>