Skip to content

Instantly share code, notes, and snippets.

Last active December 3, 2016 03:07
What would you like to do?
Number input in v4

This is a demonstration of the use of the html 'number' input to rotate a text element using d3.js v4.

This graph is part of the code samples for the update to the book D3 Tips and Tricks to version 4 of d3.js.

<!DOCTYPE html>
<meta charset="utf-8">
<title>Input (number) test</title>
<label for="nValue"
style="display: inline-block; width: 240px; text-align: right">
angle = <span id="nValue-value"></span>
<input type="number" min="0" max="360" step="5" value="0" id="nValue">
<script src=""></script>
var width = 600;
var height = 300;
var holder ="body")
.attr("width", width)
.attr("height", height);
// draw the element
.style("fill", "black")
.style("font-size", "56px")
.attr("dy", ".35em")
.attr("text-anchor", "middle")
.attr("transform", "translate(300,150) rotate(0)")
// when the input range changes update value"#nValue").on("input", function() {
// Initial update value
// adjust the text
function update(nValue) {
// adjust the value"text")
.attr("transform", "translate(300,150) rotate("+nValue+")");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment