d3/examples/hello-world/hello-event.html

48 строки
1.0 KiB
HTML
Исходник Обычный вид История

<!DOCTYPE html>
2012-10-12 03:34:17 +04:00
<meta charset="utf-8">
<title>Hello, world!</title>
Your lucky numbers are:<br>
<span></span>
<script src="../../d3.js"></script>
<script>
2010-09-28 22:34:52 +04:00
var data = [4, 8, 15, 16, 23, 42];
2012-10-12 03:34:17 +04:00
d3.select("span").selectAll("svg")
2010-09-28 22:34:52 +04:00
.data(data)
.enter().append("svg")
2010-09-28 22:34:52 +04:00
.attr("width", 100)
.attr("height", 100)
.append("text")
2010-09-28 22:34:52 +04:00
.attr("x", "50%")
.attr("y", "50%")
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.attr("fill", "white")
.attr("stroke", "black")
.attr("stroke-width", 1.5)
.attr("cursor", "pointer")
.style("font", "36pt Comic Sans MS")
.style("text-shadow", "3px 3px 3px rgba(0,0,0,.4)")
.text(function(d) { return d; })
.on("click", click)
.on("mouseover", mouseover)
.on("mouseout", mouseout);
function click(d, i) {
console.log("click", d, i);
}
function mouseover(d, i) {
d3.select(this)
.attr("fill", "brown")
.attr("stroke", "grey");
}
function mouseout(d, i) {
d3.select(this)
.attr("fill", "orange");
}
2010-09-28 22:34:52 +04:00
2012-10-12 03:34:17 +04:00
</script>