-
Notifications
You must be signed in to change notification settings - Fork 0
/
de_practice1 .html
76 lines (53 loc) · 1.7 KB
/
de_practice1 .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
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<title>D3 Tutorial</title>
<script src="https://d3js.org/d3.v4.js"></script>
<style>
svg rect {
fill:rgb(18, 223, 223);
}
svg text {
fill: blue;
font-size: larger;
text-anchor: end;
}
</style>
</head>
<body>
<button onclick="drawgraph()">Show Graph</button>
<br><br><br><br>
<svg id="svg"></svg>
<script>
function drawgraph() {
var s1 = parseInt(prompt("Enter data (max 100)"))
var s2 = parseInt(prompt("Enter data (max 100)"))
var s3 = parseInt(prompt("Enter data (max 100)"))
var s4 = parseInt(prompt("Enter data (max 100)"))
var s5 = parseInt(prompt("Enter data (max 100)"))
var dataset = [s1, s2, s3, s4, s5];
var barHeight = 45;
var width = 1100;
var scaleFactor = 10;
var graph = d3.select("svg")
.attr('height', barHeight * dataset.length)
.attr('width', width)
var bar=graph.selectAll('g')
.data(dataset)
.enter()
.append('g')
.attr('transform',function(d , i){
return 'translate(0,'+i*barHeight+')'
}
);
bar.append('rect')
.attr('height',barHeight-5)
.attr('width',function(d){ return d;})
bar.append('text')
.attr('x',function(d){return d-10;})
.attr('y',function(d){ return barHeight/2})
.text(function(d){return d})
}
</script>
</body>
</html>