Created
November 24, 2015 02:11
-
-
Save d3byex/06e6b414e503578f6c58 to your computer and use it in GitHub Desktop.
D3byEX 8.3: Alert on Mouse Click
This file contains hidden or 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> | |
<head> | |
<meta name="description" content="D3byEX 8.3" /> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script> | |
var svg = d3.select('body').append('svg') | |
.attr({ 'width': 600, 'height': 600 }); | |
var data = [30, 20, 40]; | |
var x = 0; | |
svg.selectAll('circle') | |
.data(data) | |
.enter() | |
.append('circle') | |
.attr('fill', 'steelblue') | |
.each(function (d, i) { | |
d3.select(this).attr({ | |
cx: x += (d + 5), | |
cy: 40, | |
r: d / 2 | |
}); | |
}) | |
.on('mouseenter', function () { | |
d3.select(this).attr('fill', 'red'); | |
}) | |
.on('mouseout', function () { | |
d3.select(this).attr('fill', 'steelblue'); | |
}) | |
.on('click', function (d, i) { | |
alert(d + ' ' + i); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment