javascript - How to add circles onto line chart path d3.js - Stack Overflow

Here is my chart;I'm trying to add a circle on each data point along the line path, but can't

Here is my chart;

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

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

Share Improve this question edited Aug 3, 2016 at 15:32 Tim B 1,9831 gold badge21 silver badges21 bronze badges asked Aug 3, 2016 at 15:21 alexcalexc 1,3202 gold badges18 silver badges46 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744242921a4564790.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信