-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (49 loc) · 1.34 KB
/
index.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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Simple Bar Chart</title>
<script type="text/javascript" src="https://d3js.org/d3.v5.min.js"></script>
<style></style>
</head>
<body>
<div id="container" class="svg-container"></div>
<script>
//------------------------SVG PREPARATION------------------------//
var width = 960;
var height = 500;
var adj = 20;
// we are appending SVG first
var svg = d3.select("div#container").append("svg")
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "-" + adj + " -"+ adj + " " + (width + adj) + " " + (height + adj))
.style("padding", 5)
.style("margin", 5)
.classed("svg-content", true);
//-----------------------DATA PREPARATION------------------------//
var dataset = d3.csv("data.csv");
dataset.then(function(data) {
data.map(function(d) {
d.val = +d.val;
return d;});
});
console.log(dataset);
//---------------------------BAR CHART---------------------------//
dataset.then(function(data) {
svg.selectAll("div")
.data(data)
.enter()
.append("rect")
.attr("class", "bar")
.attr("x", function (d, i) {
for (i>0; i < data.length; i++) {
return i * 21;
}
})
.attr("y", function (d) {
return height - (d.val*10);
})
.attr("width", 20)
.attr("height", function (d) {
return d.val*10;
});
});