Javascript d3.js:异常错误

Javascript d3.js:异常错误,javascript,d3.js,Javascript,D3.js,我有这个d3.js项目甜甜圈图表。由于某些原因,我无法访问onmousemove中的数据。i值变为零是我在该事件中传递的所有函数。我想访问鼠标移动的特定切片的数据 我如何解决这个问题?有人请hlp 以下是我目前的代码: piesvg.selectAll("path") .data(pie(data)) .enter().append("g") .attr('class', 'slice') var slice = d3.selectAll('g.slice') .append('pa

我有这个d3.js项目甜甜圈图表。由于某些原因,我无法访问
onmousemove
中的数据。
i
值变为零是我在该事件中传递的所有函数。我想访问鼠标移动的特定切片的数据

我如何解决这个问题?有人请hlp

以下是我目前的代码:

piesvg.selectAll("path")
.data(pie(data))
  .enter().append("g")
.attr('class', 'slice')

 var slice = d3.selectAll('g.slice')
  .append('path')
  .each(function(d) {
    d.outerRadius = outerRadius - 20;
  })
  .attr("d", arc)
  .attr('fill', function(d, i) {
    return colorspie(i)
  })
  .on("mouseover", arcTween(outerRadius, 0))
  .on("mouseout", arcTween(outerRadius - 20, 150)) 
  .on("mousemove", function(data){
    piesvg.select(".text-tooltip")
     .attr("fill", function(d,i){return colorspie(i)})
     .text(function(d, i){return d[i].domain + ":" + parseInt(d[i].value * 20)}); //Considers i as 0, so no matter whichever slice the mouse is on, the data of only first one is shown
  });
以下是完整的代码:

我不知道如何在js fiddle中添加外部文件,所以它不起作用

以下是缺少的.tsv:

value   domain
1.3038675   Cloud
2.2541437   Networking
0.15469614  Security
0.8287293   Storage
0.7292818   Analytics
0.61878455  Intelligence
1.7016574   Infra
0.4088398   Platform

对于i,您的piesvg.select被绑定为零索引,对于d,很可能是未定义的,因为它从单个工具提示元素而不是切片中获取这些值。从片段中很难100%确定,但我怀疑您想要访问和使用切片上原始selectAll中的“数据”和“I”

.on("mousemove", function(d, i){
    piesvg.select(".text-tooltip")
     .attr("fill", colorspie(i))
     .text(d.data.domain + ":" + parseInt(d.data.value * 20));   
});

编辑为饼图切片将原始数据存储在d.data属性中^ ^

你能给出一个可用的代码吗我把代码放在这里:我不知道如何在FIDLE中添加外部.tsv文件…..添加数据不起作用,你能告诉我你在寻找什么其他信息以便我能更新这个吗?我的意思是用
数据替换
d
你试过上面的代码片段了吗?如果那不起作用,你会大叫。。。需要在Cyril询问时添加一个JSFIDLE,这样人们就可以随意浏览而不是仅仅盯着你的代码嗨,请检查我是否更新了问题。填充不起作用,因为我无法在那里添加外部数据文件。对不起。。。