D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
WilliamQLiu
Full window
Github gist
D3 Colors
<!DOCTYPE html> <!-- D3 has a lot of neat ways to manipulate color https://github.com/mbostock/d3/wiki/Colors --> <html> <head> <!-- Load D3 from site --> <script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> <!-- CSS (Styling) --> <style type="text/css"> </style> </head> <body> <!-- Begin Javascript --> <script type="text/javascript"> ////////// COLORS ////////// // Create a color value mycolor = d3.rgb("#ffffff"); // Pass in Hex mycolor = d3.rgb(12, 67, 199); // Red, Green, Blue mycolor = d3.hsl(0, 100, 50); // Hue-Saturation-Lightness (e.g. red) mycolor = d3.hcl(-97, 32, 52); // steelblue mycolor = d3.lab(52, -4, -32); // Lab color space (l, a, b); steelblue d3.select("body").style("background-color", mycolor) // set background color // Make brighter and darker - Can be used for hovers darkercolor = mycolor.darker(0.1); lightercolor = mycolor.brighter(0.1); ////////// DISPLAY COLORS ////////// var svg = d3.select("body").append("svg") .attr({ width: window.innerWidth, height: window.innerHeight }); //var color = d3.scale.category10(); // d3 has built-in Colors //var color = d3.scale.category20(); // d3 has built-in Colors - Color Set 1 //var color = d3.scale.category20b(); // d3 has built-in Colors - Color Set 2 var color = d3.scale.category20c(); // d3 has built-in Colors - Color Set 3 var dataset = d3.range(20); var barWidth = window.innerWidth / dataset.length; // Print out colors svg.selectAll("rect") .data(dataset) .enter() .append("rect") .attr({ width: barWidth, height: window.innerHeight, y: 0, x: function (d, i) { return barWidth * i; }, fill: color }); </script> </body> </html>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js