-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_tutorial.html
More file actions
47 lines (33 loc) · 1.24 KB
/
api_tutorial.html
File metadata and controls
47 lines (33 loc) · 1.24 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="description" content="JSON"/>
<meta charset="utf-8">
<title>API</title>
<script src="https://d3js.org/d3.v6.min.js" charset="utf-8"></script>
</head>
<body>
<script>
d3.json("https://api.github.com/repos/avimhael/D3_Tutorial_Udemy/contents/MonthlySales3.json").then(function(data) {
var dataset = data
var h=100;
var w=400;
var decodedData = JSON.parse(window.atob(data.content))
function showHeader(dataset) {
d3.select("body").append("h1").text(dataset.category + " Sales (2013)")
}
function buildLine(dataset) {
var line = d3.line()
.x(function (d) {return ((d.month-20130001)/3.25)})
.y(function (d) {return h-d.sales; })
var svg = d3.select("body").append("svg").attr("width",w).attr("height",h)
svg.append("path").datum(dataset.monthlySales).attr("class","line").attr("d",line).attr("fill","none").attr("stroke","purple").attr("stroke-width","2")
}
decodedData.contents.forEach(function(dataset) {
showHeader(dataset)
buildLine(dataset)
})
})
</script>
</body>
</html>