D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
voigtd
Full window
Github gist
d3 vertical bar graph
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; } #chart { shape-rendering: crispEdges; display: block; margin: 0 auto; margin-top: 100px; } </style> </head> <body> <script> const data = [100, 200, 175, 200, 120]; const w = 350; const h = 250; const x = d3.scaleLinear() .domain([0, data.length]) .range([0, w]); const y = d3.scaleLinear() .domain([0, d3.max(data)]) .range([0, h]); const svg = d3.select('body') .append('svg') .attr('id', 'chart') .attr('width', w) .attr('height', h); svg.selectAll('.bar') .data(data).enter() .append('rect') .classed('.bar', true) .attr('x', (d, i) => x(i)) .attr('y', d => h - y(d)) .attr('width', x(1) - 2) .attr('height', d => y(d)) .attr('fill', 'steelblue') .attr('stroke', 'black'); </script> </body>
https://d3js.org/d3.v4.min.js