forked from jfreyre's block: D3.js - Create a custom color scale
Last active
July 3, 2020 20:48
-
-
Save chule/779e6a30d009be812e7b43a50c84375b to your computer and use it in GitHub Desktop.
green, orange and red color scale
This file contains 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
license: mit |
This file contains 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 charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<style type="text/css" media="screen"> | |
div { | |
width:60px; | |
height: 60px; | |
float: left; | |
margin: 1px; | |
} | |
</style> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v5.js"></script> | |
<script type="text/javascript"> | |
var body = d3.select("body"), | |
length = 10, | |
color = d3.scaleLinear() | |
.domain([100,50,25,0]) | |
.range(["red", "orange", "green", "lightgreen"]); | |
for (var i = 0; i < length; i++) { | |
body.append('div').attr('style', function (d) { | |
return 'background-color: ' + color(i*10); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment