D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
basilesimon
Full window
Github gist
Arrowheads at each end of axis
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <script src="https://unpkg.com/d3-jetpack"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <script> const svg = d3 .select('body') .append('svg') .attr('width', 500) .attr('height', 500); // Arrowhead defs svg.append('defs') .append('marker') .at({ id: 'arrowhead-right', refX: 5, refY: 5, markerWidth: 16, markerHeight: 13, }) .append('path') .at({ d: 'M 0 0 L 5 5 L 0 10', stroke: 'black', strokeWidth: 1, fill: 'none', }); svg.append('defs') .append('marker') .at({ id: 'arrowhead-left', refX: 0, refY: 5, markerWidth: 16, markerHeight: 13, }) .append('path') .at({ d: 'M 5 0 L 0 5 L 5 10', stroke: 'black', strokeWidth: 1, fill: 'none', }); const x = d3 .scaleLinear() .range([0, 400]) .domain([0, 10]); const xa = svg .append('g') .attr('class', 'axis') .attr('transform', 'translate(50,250)') .call(d3.axisBottom(x) .tickSizeInner(0) .tickPadding(6) .tickSizeOuter(0)); // append the markers at the start and end of our axis path xa.select('path').at({ markerEnd: 'url(#arrowhead-right)' }); xa.select('path').at({ markerStart: 'url(#arrowhead-left)' }); </script> </body>
https://d3js.org/d3.v4.min.js
https://unpkg.com/d3-jetpack