D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jamesleesaunders
Full window
Github gist
D3 : Colour Ranges - Column Chart
Colour Ranges - Column Chart
<!DOCTYPE html> <html> <head> <title>D3 : Colours Ranges - Column Chart</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script> <style type="text/css"> #chartholder { height: 400px; width: 600px; } .bar { display: inline-block; width: 50px; height: 10px; margin-right: 2px; background-color: teal; } </style> </head> <body> <div id="chartholder"></div> <script type="text/javascript"> var data = d3.range(10).map(function () { return Math.random(); }); //var colors = ['rgb(228,26,28)','rgb(55,126,184)','rgb(77,175,74)','rgb(152,78,163)','rgb(255,127,0)']; var colors = ["#FF0000", "#00FFFF"]; var colorIndex = d3.scale.linear() .domain([0, 1]) .range(colors); var svg = d3.select('#chartholder').selectAll('div') .data(data) .enter() .append('div') .attr('class', 'bar') .style('height', function (d) { return d * 400 + 'px'; }) .style('background-color', function (d) { return colorIndex(d); }); </script> </body> </html>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js