2

Here is my chart;

http://plnkr.co/edit/Cej2NcyUWysAsKiMAEXj?p=preview

I'm trying to add a circle on each data point along the line path, but can't seem to find a way to do it.

Here is the code I'm using to draw the circles/line for the graph;

  var selectLine = svg.selectAll(".line")
    .data([data])

  var selectCircle = svg.selectAll(".circle")
    .data([data])

  svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis)

  svg.append("g")
    .attr("class", "y axis")
    .call(yAxis)

  selectLine.enter().append("path")
    .attr("class", "line")
    .attr("d", line);

  selectCircle.enter().append("circle")
    .attr("class", "circle")
    .attr("r", 3.5)
    .attr("cx", function(d) {
      return x(new Date(2016, moment(d.date, 'MMMM').format('M') - 1, 1))
    })
    .attr("cy", function(d) {
      return y(d.close)
    })

Any help/advice is much appreciated!

Thanks

1 Answer 1

5

Change

var selectCircle = svg.selectAll(".circle")
.data([data])

to

var selectCircle = svg.selectAll(".circle")
.data(data)

Because you want each point to be treated as separate item

See http://plnkr.co/edit/NCQyDtykbxjlvK687WIu?p=preview

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.