score:3

Accepted answer

Just get the index you are at and return the corresponding value from the y_axis_values array :

var x_axis_values = [0, 1, 2, 3];

var y_axis_values = [2, 3, 4, 5];

var svgContainer = d3.select("body").append("svg")
  .attr("width", 200)
  .attr("height", 200);

var circles = svgContainer.selectAll("circle")

.data(x_axis_values)
  .enter()
  .append("circle");


var circleAttributes = circles
  .attr("cx", function(d) {
    return d;
  })
  .attr("cx", function(d, i) { //add i here to get current index
    return y_axis_values[i]; //gets current index of x_axis_values and  gets the corresponding y_axis_values value
  })

Related Query

More Query from same tag