Sergino
Sergino

Reputation: 10838

Add points to D3 chart

I was trying to add points to this chart http://bl.ocks.org/nsonnad/4175202

countryEnter.selectAll("dot")
        .data(data)
        .enter().append("circle")
        .attr("r", 3.5)
        .attr("cx", function(d) { return x(d.year); })
        .attr("cy", function(d) { return y(d.name); });

But it is didn't work https://plnkr.co/edit/ADuZkJQrq7mjZqDZwrBe May be someone can help?

Upvotes: 0

Views: 1858

Answers (1)

Mark
Mark

Reputation: 108567

When working with a nested selection, your data call can return a part of the data. In this case the values array:

countryEnter.selectAll("dot")
  .data(function(d){
    return d.values; //<-- return just the values of your larger data-binding
  })
  .enter().append("circle")
  .attr("r", 3.5)
  .attr("cx", function(d) { return x(d.year); })
  .attr("cy", function(d) { return y(d.stat); });

Updated code.

Upvotes: 1

Related Questions