D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
blehr
Full window
Github gist
names
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; } svg { width: 100%; height: 100%; } </style> </head> <body> <svg></svg> <script> var width = 800; var height = 300; var margin = {top: 20, bottom: 40, left: 40, right: 20}; d3.csv('1880.txt', (err, data) => { var names = data.slice(0, 10).map(d => { d.occurrences = +d.occurrences; return d; }); var xScale = d3.scaleBand() .domain(names.map(d => d.name)) .rangeRound([margin.left, width - margin.right]) .padding(0.1) var yScale = d3.scaleLinear() .domain(d3.extent(names, d => d.occurrences)) .range([height - margin.bottom, margin.top]); var svg = d3.select('svg'); svg.append("g") .attr("transform", "translate(0," + height + ")") .call(d3.axisBottom(xScale)); svg.append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")") .call(d3.axisLeft(yScale)) var rect = svg.selectAll('rect') .data(names) .enter().append('rect') .attr('width', xScale.bandwidth()) .attr('height', d => height - yScale(+d.occurrences)) .attr('x', d => xScale(d.name)) .attr('y', d => yScale(d.occurrences)) .attr('fill', 'blue') .attr('stroke', '#FFF'); }); </script> </body>
https://d3js.org/d3.v4.min.js