D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
johna-mahna
Full window
Github gist
curran class ex 1
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> var width = 960; var height = 500; var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height); //From July 2005 through June 2015. var monaData = [ { name: "total with extremist connection", value: 279 }, { name: "right-wing extremism", value: 260 }, { name: "white supremacists", value: 215 } ] var margin = { left: 100, right: 100, top: 100, bottom: 100 } var innerWidth = width - margin.left - margin.right; var innerHeight = height - margin.top - margin.bottom; var xValue = d => d.value; var yValue = d => d.name; var xScale = d3.scaleLinear() .domain([0, d3.max(monaData, d => d.value)]) .range([0, innerWidth]); var yScale = d3.scaleBand() .domain(monaData.map(d => d.name)) .range([innerHeight, 0]) .padding(4); svg.selectAll('rect').data(monaData) .enter().append('rect') .attr('x', d => xScale(xValue(d))) .attr('y', d => yValue(d)) .attr('width', d => xScale(xValue(d))) .attr('height', yScale.bandwidth()) .attr('fill', 'black') </script> </body>
https://d3js.org/d3.v4.min.js