円で遊ぶ2 円にマウスを当てると、色が変わる。
-
-
Save marimiya/395bbdc327682cebf678 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Circle test 2</title> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"> | |
// <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"> | |
</script> | |
<script> | |
var dataset = [11,25,45,30,33]; | |
var w = 500; | |
var h = 200; | |
var svg = d3.select("body").append("svg").attr({width:w, height:h}); | |
svg.selectAll("circle") | |
.data(dataset) | |
.enter() | |
.append("circle") | |
.on("mouseover", function(d) { | |
d3.select(this).attr("fill","orange"); | |
}) | |
.on("mouseout", function(d) { | |
d3.select(this).attr("fill","red"); | |
}) | |
.on("click", function(d) { | |
var rs = d3.select(this).attr("r"); | |
alert(rs); | |
}) | |
.attr({ | |
cx: function(d, i) { return 50 + (i * 100);}, | |
cy: h/2, | |
r: function(d) { return d; }, | |
fill: "red" | |
}); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment