admin管理员组文章数量:1400211
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 badges1 Answer
Reset to default 5Change
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
本文标签: javascriptHow to add circles onto line chart path d3jsStack Overflow
版权声明:本文标题:javascript - How to add circles onto line chart path d3.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744242920a2596874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论