Built with blockbuilder.org
forked from anonymous's block: Adding Click for Tick Labels
Built with blockbuilder.org
forked from anonymous's block: Adding Click for Tick Labels
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
.axis path, .axis line { fill: none; stroke: black; } | |
</style> | |
</head> | |
<body> | |
<script> | |
// Feel free to change or delete any of the code you see! | |
var svg = d3.select("body") | |
.append("svg") | |
.attr("width", 950) | |
.attr("height", 500); | |
var scale = d3.scale.linear().domain([0, 10]).range([0, 900]); | |
var axis = d3.svg.axis().scale(scale); | |
var g = svg.append("g").attr("transform", "translate(15, 200)"); | |
g.attr("class", "axis"); | |
g.call(axis); | |
d3.selectAll(".tick text").on("click", doclick); | |
function doclick() { | |
if (scale.domain()[1] - scale.domain()[0] == 10) { | |
scale.domain([0, 100]); | |
} | |
else { | |
scale.domain([0, 10]); | |
} | |
g.call(axis); | |
d3.selectAll(".tick text").on("click", doclick); | |
} | |
</script> | |
</body> |