1
根據this D3.js雷達圖表的例子,我試圖找到更高級的工具提示。我想顯示一個名稱和數字列表,其中一些基於我的數據集,而不僅僅是一個數字。D3.js雷達圖表工具提示
的問題是在這部分代碼:
blobCircleWrapper.selectAll(".radarInvisibleCircle")
.data(function(d,i) { return d; })
.enter().append("circle")
.attr("class", "radarInvisibleCircle")
.attr("r", cfg.dotRadius*1.5)
.attr("cx", function(d,i){ return rScale(d.value) * Math.cos(angleSlice*i - Math.PI/2); })
.attr("cy", function(d,i){ return rScale(d.value) * Math.sin(angleSlice*i - Math.PI/2); })
.style("fill", "none")
.style("pointer-events", "all")
.on("click", function(d,i) { // TOOLTIP WITH SUBJECTS AND AVERAGES HERE
newX = parseFloat(d3.select(this).attr('cx')) - 10;
newY = parseFloat(d3.select(this).attr('cy')) - 10;
tooltip
.attr('x', newX)
.attr('y', newY)
.html(d.value+ "<br>" + "To:")
.transition().duration(200)
.style('opacity', 1);
})
.on("mouseout", function(){
tooltip.transition().duration(200)
.style("opacity", 0);
});
//Set up the small tooltip for when you hover over a circle
var tooltip = g.append("text")
.attr("class", "tooltip")
.style("opacity", 0);
工具提示設置爲雷達的圈子,當我嘗試創建一個div
元素text
元素的替代,工具提示停止顯示,雖然元素被創建並且定位良好。我正在嘗試這樣的事情:
我確定我在這裏錯過了一些屬性,但有沒有辦法讓更完整的工具提示?謝謝。
是啊,你說得對。創建這些工具提示時,我總是傾向於迷惑自己。我總是將'div'元素附加到SVG,而不是附加到body。我現在不會忘記它。謝謝。在附註中,你認爲這些是最好的工具提示類型嗎? –
@ Shoplifter.Doe好吧,「最佳類型」是基於意見的......我只能說這些是我在代碼中使用的工具提示。 –
是的,我知道,但我歡迎您提出意見,因爲您是一位熟練的D3.js用戶和貢獻者。謝謝 :) –