-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.html
46 lines (38 loc) · 1.33 KB
/
2.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
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ejemplo 2</title>
<script src="https://d3js.org/d3.v5.min.js"></script>
</head>
<body>
<div id="chart" style="width:100%;height: 400px;border:1px solid gray;"></div>
<script>
function drawChart(){
console.log("a")
var width = document.getElementById('chart').offsetWidth;
var height = document.getElementById('chart').offsetHeight;
var padding = 10;
var realWidth = width - (padding * 2)
var realHeight = height - (padding * 2)
d3.select("svg").remove();
var svg = d3.select("#chart").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + padding/2 + "," + padding/2 + ")");
svg.append("rect")
.attr('class', 'bar')
.attr('x', realWidth/4)
.attr('y', realHeight/4)
.attr('width', realWidth/2)
.attr('height', realHeight/2)
}
window.onresize = drawChart;
drawChart();
</script>
</body>
</html>
<!--
-->