我是d3js的新手,在這裏缺少一些基本的東西。在D3子彈圖中使用來自JSON數據的顏色
以我JSON數據,我添加了一個顏色元件,barColor(到第二組值):
[ {"title":"AMER Revenue","subtitle":"703 US$, in thousands","ranges":[840,945,1200],"measures":[703],"markers":[1050]}, {"title":"AMER COGS","subtitle":"587 US$, in thousands","ranges":[1200,832.5,740],"measures":[587],"markers":[925],"barColor":["red"]} ]
的JSON barColor數據被正確地讀爲我可以在各種使用它的背景下,只是不在我想要的地方。
這裏是我有(完整的註釋掉其他成功的測試)。
/* Select the bars and use the color from the json data */
d3.selectAll(".bullet .measure.s0")
//.style("fill", "red"); //This works. All .measure.s0 bars set to red.
.style("fill", function(d) { return d.barColor; }); //Why doesn't this work?
具體來說,它是d3.selectAll(」子彈.measure.s0 「)風格(」 補「,function(d){return d.barColor;});這不符合我的期望。也就是說,我期望d.barColor將measure.s0的填充更改爲紅色。
我花了不少時間閱讀和搜索,但似乎卡住了。
在此先感謝您的任何指導。
@ user2679918這個工作適合你嗎?如果沒有,請告訴我們,我們可以解決一些問題。 – BDD