Skip to content

Instantly share code, notes, and snippets.

@chule
Last active July 3, 2020 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chule/779e6a30d009be812e7b43a50c84375b to your computer and use it in GitHub Desktop.
Save chule/779e6a30d009be812e7b43a50c84375b to your computer and use it in GitHub Desktop.
green, orange and red color scale
license: mit
<!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