I made a couple of changes to your example, and you can see the results at http://jsbin.com/edatol/2/edit .
Firstly, I changed your data a bit. This is basically just a style, but itβs easier for me to work with objects, not arrays:
Then you can find your domains and ranges, like this:
var xDomain = d3.extent(dataset, function(i) { return ix; }); var maxY = d3.max(dataset, function(i) { return Math.max(i.y1, i.y2); });
Then, to add a few y-values, you just need to add an extra circle with the corresponding values. I gave them different classes so you can use them to select them if you want to do transitions or updates later.
//Create circles svg.selectAll(".y1") .data(dataset) .enter() .append("circle") .attr("cx", function(d) { return xScale(dx); }) .attr("cy", function(d) { return yScale(d.y1); }) .attr("class", "y1") .attr("r", 2); //Create circles svg.selectAll(".y2") .data(dataset) .enter() .append("circle") .attr("cx", function(d) { return xScale(dx); }) .attr("cy", function(d) { return yScale(d.y2); }) .attr("class", "y2") .attr("r", 2);
source share