@darrion.kuhn
There are a few ways you can space data points horizontally in d3.js:
Here's an example of using a scale function to space data points horizontally using d3.scaleBand():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
var data = [10, 20, 30, 40, 50]; var width = 800; var height = 400; var xScale = d3.scaleBand() .domain(data) .range([0, width]) .padding(0.1); // Adjust the padding between data points var svg = d3.select('body') .append('svg') .attr('width', width) .attr('height', height); svg.selectAll('rect') .data(data) .enter() .append('rect') .attr('x', function(d) { return xScale(d); }) .attr('y', 0) .attr('width', xScale.bandwidth()) .attr('height', height); |
In this example, we are creating a horizontal bar chart with data points spaced evenly using d3.scaleBand(). The padding(0.1) call adjusts the spacing between data points. You can experiment with different padding values to change the spacing as needed.