-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_bubble_chart.html
68 lines (63 loc) · 1.75 KB
/
simple_bubble_chart.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3: Forced Layout chart</title>
<script type="text/javascript" src="../d3/d3.js"></script>
<style type="text/css">
</style>
</head>
</head>
<body>
<svg id="svgVisualize" width="500" height="500" style="border:1px solid Red;"></svg>
<script type="text/javascript">
var sampleData = [{
"x": 1,
"y": 5
}, {
"x": 20,
"y": 20
}, {
"x": 40,
"y": 10
}, {
"x": 60,
"y": 40
}, {
"x": 80,
"y": 5
}, {
"x": 100,
"y": 60
}];
InitChart();
function InitChart(){
var vis = d3.select("#svgVisualize");
var xRange = d3.scale.linear().range([40, 400]).domain([d3.min(sampleData, function (d) {
return (d.x);
}),
d3.max(sampleData, function (d) {
return d.x;
})]);
var yRange = d3.scale.linear().range([400, 40]).domain([d3.min(sampleData, function (d) {
return d.y;
}),
d3.max(sampleData, function (d) {
return d.y;
})]);
var xAxis = d3.svg.axis().scale(xRange);
var yAxis = d3.svg.axis().scale(yRange).orient("left");
vis.append("svg:g").call(xAxis).attr("transform", "translate(0,400)");
vis.append("svg:g").call(yAxis).attr("transform", "translate(40,0)");
var circles = vis.selectAll("circle").data(sampleData);
circles
.enter()
.insert("circle")
.attr("cx", function (d) { return xRange (d.x); })
.attr("cy", function (d) { return yRange (d.y); })
.attr("r", 10)
.style("fill", "red");
}
</script>
</body>
</html>