js折线图-定位点

D3.js line chart - positioning the dots

本文关键字:定位 折线图 js      更新时间:2023-09-26

我的工具提示点定位有问题。我正在使用一个序数X刻度,我只是不能让它工作…不确定我是否需要改变我的数据结构。任何见解将不胜感激。我在下面包含了一个JS FIDDLE链接

tooltip_container.selectAll("dot")    
    .data(dataset)         
    .enter().append("circle")                               
    .attr("r", 5) 
    .attr("cx", function(d,i) { /*  return x(d) ?? */})             
    .attr("cy", function(d,i) { /*  return y(d) ?? */}) 

JS提琴链接

如果你想为所有行创建工具提示,你需要这个

tooltip_container.selectAll("dot")    
    .data(dataset)         
    .enter().append("circle")                               
    .attr("r", 5) 
    .attr("cx", function(d,i) {   return x(d.month)  })             
    .attr("cy", function(d,i) {   return y(d.undecided) }) 
tooltip_container.selectAll("dot")    
    .data(dataset)         
    .enter().append("circle")                               
    .attr("r", 5) 
    .attr("cx", function(d,i) {   return x(d.month)  })             
    .attr("cy", function(d,i) {   return y(d.yes) }) 
tooltip_container.selectAll("dot")    
    .data(dataset)         
    .enter().append("circle")                               
    .attr("r", 5) 
    .attr("cx", function(d,i) {   return x(d.month)  })             
    .attr("cy", function(d,i) {   return y(d.no) })