javascript - D3.js 折线图 - 定位点

标签 javascript html css d3.js

我在定位工具提示点时遇到问题。我正在使用序数 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 Fiddle link

最佳答案

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

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) }) 

关于javascript - D3.js 折线图 - 定位点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32023211/

相关文章:

javascript - 如何在组合函数中传递泛型,而不是简单类型(例如 : string, 数字)

javascript - 如何利用 HTML/CSS 和 Javascript 直观地显示 Python 代码块?

css - 将事件监听器添加到 div 的标题

javascript - 如何使用 jQuery 将 HTML 标签显示为文本?

javascript - 向下滚动时显示带有动画的内容

HTML &lt;input&gt; 和 <button> 浏览器不一致

html - GridView (相同宽度/不同高度)- 3 列 | CSS

javascript - 如何使用内联 css 将 javascript 元素居中?

javascript - 使用下划线过滤 JSON

javascript - 尝试插入数组会在 angular6 中出现错误