D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
noblemillie
Full window
Github gist
vertical, horizontal axis generator
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> <div class="control-group"> <button onclick="renderAll(d3.axisBottom)"> horizontal bottom </button> <button onclick="renderAll(d3.axisTop)"> horizontal top </button> <button onclick="renderAll(d3.axisLeft)"> vertical left </button> <button onclick="renderAll(d3.axisRight)"> vertical right </button> </div> <script type="text/javascript"> var height = 500, width = 500, margin = 25, offset = 50, axisWidth = width - 2 * margin, svg; function createSvg(){ svg = d3.select("body").append("svg") .attr("class", "axis") .attr("width", width) .attr("height", height); } function renderAxis(fn, scale, i){ var axis = fn() .scale(scale) .ticks(5); svg.append("g") .attr("transform", function(){ if([d3.axisTop, d3.axisBottom].indexOf(fn) >= 0) return "translate(" + margin + "," + i * offset + ")"; else return "translate(" + i * offset + ", " + margin + ")"; }) .call(axis); } function renderAll(fn){ if(svg) svg.remove(); createSvg(); renderAxis(fn, d3.scaleLinear() .domain([0, 1000]) .range([0, axisWidth]), 1); renderAxis(fn, d3.scalePow() .exponent(2) .domain([0, 1000]) .range([0, axisWidth]), 2); renderAxis(fn, d3.scaleTime() .domain([new Date(2016, 0, 1), new Date(2017, 0, 1)]) .range([0, axisWidth]), 3); } </script> </body>
https://d3js.org/d3.v4.min.js