1
我试图绘制上线小圆圈折线图中表示的数据点,使用下面的代码:积点
// Add the scatterplot
g.selectAll("dot")
.data(newdata[0].values)
.enter().append("circle")
.attr("r", 5)
.attr("cx", function(d) {
return x(d.date);
})
.attr("cy", function(d) {
return y(d.value);
})
//.attr("stroke", "blue")
//.attr("stroke-width", 2)
//.attr("fill", "none")
.on("mouseover", function(d) {
div.transition()
.duration(200)
.style("opacity", .9);
div.html(formatTime(d.date) + "<br/>" + d.value)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
但问题是,我只能通过一次元素的值:.data(newdata[0]).values)
。这只会在一行上绘制点。我可以把整个代码循环,并使用计数器i
而不是0.但这将是一个非常糟糕的解决方案。下面是我的数据结构:
[{
"id": "primary",
"values": [{
"date": "2011-03-31T18:30:00.000Z",
"value": 58.13
}, {
"date": "2011-04-30T18:30:00.000Z",
"value": 53.98
}]
}, {
"id": "secondary",
"values": [{
"date": "2011-03-31T18:30:00.000Z",
"value": 28.13
}, {
"date": "2011-04-30T18:30:00.000Z",
"value": 35.13
}]
}];
请建议做什么! :)
辉煌,我怎么没有想起它!谢谢。 :) – Rishabh