Ok, this works great, but how do I get the dots to the same color as
the lines.. specifically, what's the best way to get the index of the
line you're on (the index provided to the dots functions I believe is
the index of the dot on the line, not the line)... here's my code:
var g = vis.selectAll('g.line')
.data(data)
.enter().append('svg:g')
.attr('class', 'line');
var lines = g.append('svg:path')
.attr('d', d3.svg.line()
.x(function(d) { return x(d.x) })
.y(function(d) { return y(d.y) })
)
.attr('fill', 'none')
.attr('stroke-width', 2)
.attr('stroke', function(d, i) {
return colors[i * 2 % 20];
});
var dots = g.selectAll('circle')
.data(function(d) { return d; })
.enter().append('svg:circle')
.attr('cx', function(d) { return x(d.x); })
.attr('cy', function(d) { return y(d.y); })
.attr('r', 2);
Also, I'm using this on an interactive chart where there's an update
function with this code to update the lines/dots, I feel like I'm
doing something wrong, though I am getting the correct results (but to
me, working does not imply "right"):
g.data(data);
lines
.data(data)
.attr('d', d3.svg.line()
.x(function(d) { return x(d.x) })
.y(function(d) { return y(d.y) })
);
dots
.data(function(d) { return d })
.attr('cy', function(d) { return y(d.y) });
Thanks in advance for the help.
On Jul 18, 5:30 pm, Mike Bostock <
mbost...@cs.stanford.edu> wrote:
> The cardinality oflinesand circles are different. In the case oflines, you map an array of data (e.g., [1, 2, 3, …]) to a single line.
> With circles, you map a number (e.g., 1) to a single circle. So, if
> you have multiplelines, then your data probably looks like a