D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
mtranggit
Full window
Github gist
Create axes with d3
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 { background: lightgray; border: 1px solid black; width: 425px; height: 625px; } </style> </head> <body> <div class="chart"></div> <script> var margin = {top: 10, right: 25, bottom: 35, left: 40 } var width = 425 - margin.left - margin.right; var height = 625 - margin.top - margin.bottom; var svg = d3.select('.chart') .append('svg') .attr('width', width + margin.left + margin.right) .attr('height', height + margin.top + margin.bottom) .append('g') .attr('transform', `translate(${margin.left}, ${margin.top})`) svg.append('rect') .attr('width', width) .attr('height', height) .attr('fill', 'lightblue') .attr('stroke', 'lightgreen') // draw xAxis var xScale = d3.scaleTime() .domain([new Date(2017,8,21,9,0), new Date(2017,8,21,10,0)]) .range([0, width]) var xAxis = d3.axisBottom(xScale) .ticks(5) .tickSize(10) .tickPadding(5) svg.append('g') .attr('transform', `translate(${0}, ${height})`) .call(xAxis) // draw yAxis var yScale = d3.scaleLinear() .domain([0, 100]) .range([height, 0]) var yAxis = d3.axisLeft(yScale) .ticks(10) .tickSize(10) .tickPadding(10) svg.append('g') .attr('transform', `transform(${margin.left}, ${margin.top})`) .call(yAxis) </script> </body>
https://d3js.org/d3.v4.min.js