Built with blockbuilder.org
Last active
May 1, 2019 23:04
-
-
Save ericd9799/d7534b92d9c30edf4726aadd49cffabe to your computer and use it in GitHub Desktop.
D3 V5 Color Schemes
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> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v5.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
</style> | |
</head> | |
<body> | |
<script> | |
var margin={top:50,right:50,bottom:50,left:50}; | |
var width = 960 - margin.left - margin.right; | |
var height = 525 - margin.top - margin.bottom; | |
var circleArray = []; | |
var colorArray = [d3.schemeCategory10, d3.schemeAccent]; | |
var svg = d3.select("body").append("svg") | |
.style("border", "solid") | |
.attr("width", width+margin.left+margin.right) | |
.attr("height", height+margin.top+margin.bottom); | |
var g = svg.append("g") | |
.attr("transform", "translate("+margin.top+","+margin.left+")"); | |
var colorScheme = d3.scaleOrdinal(colorArray[0]); | |
for(i = 0; i < colorArray[0].length; i++){ | |
var circleDict = {}; | |
circleDict.cx = (i * 15) / 0.2; | |
circleDict.cy = 15; | |
circleDict.r = 15; | |
circleDict.color = colorScheme(i); | |
circleArray.push(circleDict); | |
} | |
g.append("g").selectAll("circle").data(circleArray).enter().append("circle") | |
.attr("cx", function(d){return d.cx;}) | |
.attr("cy", function(d){return d.cy;}) | |
.attr("r", function(d){return d.r;}) | |
.attr("fill", function(d){return d.color;}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment