1
我的條形圖非常好。但是仍然有一些調整。我遇到了問題,使條形碼標籤正確對齊&對於何時添加額外數據仍然保持響應。D3js工具提示沒有正確生成
因此,我決定刪除這些標籤,然後對鼠標懸停進行工具提示。但是我發現它沒有填充正確的數據。它只填充綠條(全局)。當我將鼠標懸停在藍色(本地)欄上時,我會得到與全局值相同的工具提示。
似乎它正在爲整個集合生成工具提示,而不是單個工具欄。
問題#1如何讓它爲單個欄而不是整個組生成正確的數據?
問題#2如何在工具提示中有多個值。您將從我的小提琴中看到,它目前僅指定每次點擊費用,並且不會爲搜索量生成數據。工具提示只能提取一條動態數據嗎?這看起來不正確。
sets.append("rect")
.attr("class","local")
.attr("width", xScale.rangeBand()/2)
.attr("y", function(d) {
return yScale(d.local);
})
.attr("x", xScale.rangeBand()/2)
.attr("height", function(d){
return h - yScale(d.local);
})
.attr("fill", colors[0][1])
.on("mouseover", function(d,i) {
//Get this bar's x/y values, then augment for the tooltip
var xPosition = parseFloat(xScale(i) + xScale.rangeBand());
var yPosition = h/2;
//Update Tooltip Position & value
d3.select("#tooltip")
.style("left", xPosition + "px")
.style("top", yPosition + "px")
.select("#cpcVal")
.text(d.cpc)
.select("#volVal")
.text(d.local);
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function() {
//Remove the tooltip
d3.select("#tooltip").classed("hidden", true);
})
;
sets.append("rect")
.attr("class","global")
.attr("width", xScale.rangeBand()/2)
.attr("y", function(d) {
return yScale(d.global);
})
.attr("height", function(d){
return h - yScale(d.global);
})
.attr("fill", colors[1][1])
.on("mouseover", function(d,i) {
//Get this bar's x/y values, then augment for the tooltip
var xPosition = parseFloat(xScale(i) + xScale.rangeBand());
var yPosition = h/2;
//Update Tooltip Position & value
d3.select("#tooltip")
.style("left", xPosition + "px")
.style("top", yPosition + "px")
.select("#cpcVal")
.text(d.cpc)
.select("#volVal")
.text(d.global);
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function() {
//Remove the tooltip
d3.select("#tooltip").classed("hidden", true);
})
;
感謝您的回覆。我曾嘗試過類似的東西。我又做了,但我仍然得到相同的結果。 - >小提琴:http://jsfiddle.net/enigmarm/weXNd/2/ – EnigmaRM 2013-04-24 17:28:39
你在第二個選擇中忘記了'tooltip'前面的'#'符號。 – 2013-04-24 18:02:30
哈哈。哦,天哪。這種愚蠢的錯誤總是讓我感動。謝謝! – EnigmaRM 2013-04-24 18:11:56