d3js: Create an HTML select box using d3.js and create a paragraph referencing the selection.
Last active
May 27, 2021 09:39
-
-
Save jfreels/6734823 to your computer and use it in GitHub Desktop.
d3js: Create an HTML select box using d3.js and create a paragraph referencing the selection.
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> | |
<meta charset='utf-8'> | |
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<link rel='stylesheet' href='style.css'> | |
</head> | |
<body> | |
<script type='text/javascript' src='script.js'></script> | |
</body> | |
</html> |
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
var data = ["Option 1", "Option 2", "Option 3"]; | |
var select = d3.select('body') | |
.append('select') | |
.attr('class','select') | |
.on('change',onchange) | |
var options = select | |
.selectAll('option') | |
.data(data).enter() | |
.append('option') | |
.text(function (d) { return d; }); | |
function onchange() { | |
selectValue = d3.select('select').property('value') | |
d3.select('body') | |
.append('p') | |
.text(selectValue + ' is the last selected option.') | |
}; |
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
/* CSS Here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks