简体   繁体   English

如何在用于在D3中显示饼图的数据中添加键?

[英]How to add keys to data that is used to display pie chart in D3?

I have an array called countArray which simply just consists of numbers. 我有一个名为countArray的数组,它仅由数字组成。 I also have a parallel array called descArray which is essentially the keys to those values (the numbers in the countArray). 我还有一个名为descArray的并行数组,它实际上是这些值(countArray中的数字)的键。 In D3, I draw my pie chart using the values in countArray. 在D3中,我使用countArray中的值绘制饼图。

var vis = d3.select(divId).append("svg:svg").data([countArray]).attr("width",                 w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")");

When I hover over an arc in the pie chart and console.log(d) , I would see that the value and the key for the specific arc is the same. 当我将鼠标悬停在饼图和console.log(d)的弧上时,我会看到特定弧的值和键是相同的。 I want to know a way to append the key data from my descArray onto d . 我想知道一种将密钥数据从descArrayd

            arcs.append("svg:path")
             .on("mouseover", function(d) {
                console.log(d);
            })

Nvm, I figured it out. Nvm,我知道了。

 var vis = d3.select(divId).append("svg:svg").data([descArray]).attr("width",                 w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")");

the values were actually binded elsewhere. 值实际上绑定在其他地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM