D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
nehabandal
Full window
Github gist
Loading data
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> // Feel free to change or delete any of the code you see in this editor! var w = 600; var h = 250; // var colData = [ 5, 10, 13, 19, 21, 25, 22, 18, 15, 13, // 11, 12, 15, 20, 18, 17, 16, 18, 23, 25 ]; var colData = []; d3.csv("graduates.csv", function(error,data) { data.forEach(function(node) { var val = node.Asians; colData.push(val); }); // out = colData[0]; // console.log(colData[0]); }); var xScale = d3.scaleBand() .domain(d3.range(colData.length)) .rangeRound([0, w]) .paddingInner(0.05); var yScale = d3.scaleLinear() .domain([0, d3.max(colData)]) .range([0, h]); //Create SVG element var svg = d3.select("body") .append("svg") .attr("width", w) .attr("height", h); //Create bars svg.selectAll("rect") .data(colData) .enter() .append("rect") .attr("x", function(d, i) { return xScale(i); }) .attr("y", function(d) { return h - yScale(d); }) .attr("width", xScale.bandwidth()) .attr("height", function(d) { return yScale(d); }) .attr("fill", function(d) { return "rgb(0, 0, " + Math.round(d * 10) + ")"; }); //Create labels // svg.selectAll("text") // .data(dataset) // .enter() // .append("text") // .text(function(d) { // return d; // }) // .attr("text-anchor", "middle") // .attr("x", function(d, i) { // return xScale(i) + xScale.bandwidth() / 2; // }) // .attr("y", function(d) { // return h - yScale(d) + 14; // }) // .attr("font-family", "sans-serif") // .attr("font-size", "11px") // .attr("fill", "white"); </script> </body>
https://d3js.org/d3.v4.min.js