我正在研究一個應用程序 - 其中每列可能包含不同類型的主題。d3.js不同顏色/圖例的堆疊圖表
這個當前的演示顯示了一個普通的堆棧圖。
但是,如果我想建立每列不同的主題/傳說/顏色。最好的辦法是什麼?
會是創建一個多維陣列的顏色陣列的情況下
var color = d3.scale.ordinal()
.range(["#20b2aa", "#fa8072", "#87ceeb", "#daa520", "#00bfff", "#dc143c", "#87cefa", "#90ee90", "#add8e6", "#d3d3d3"]);
state.selectAll("rect")
.data(function(d) {
return d.ages;
})
.enter().append("rect")
.attr("width", x.rangeBand())
.attr("y", function(d) { return y(d.y1); })
.attr("height", function(d) { return y(d.y0) - y(d.y1); })
.style("fill", function(d) { return color(d.name); })//;
.on("mouseover", function(d) {
//Get this bar's x/y values, then augment for the tooltip
var xPosition = parseFloat(d3.select(this.parentNode).attr("x")) + (x.rangeBand()/2) + 50;
var yPosition = parseFloat(d3.select(this).attr("y"))/2 + height/2;
//Update the tooltip position and value
d3.select("#tooltip")
.style("left", xPosition + "px")
.style("top", yPosition + "px")
.select("#value")
.text(d.name +" : " + d.hours);
//Show the tooltip
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function() {
//Hide the tooltip
d3.select("#tooltip").classed("hidden", true);
})
這聽起來不像是這種類型的圖表適合您想要顯示的內容。也許是一系列或嵌套的[甜甜圈圖表](http://bl.ocks.org/mbostock/3887193)? –
啊。我確實有一系列已經表示數據的嵌套圓環圖。我想知道如何壓縮它們以形成堆疊圖表。所以信息可以一目瞭然。我想我可以將信息顯示爲一系列單獨的堆積圖表。 –
也許[堆積面積圖](http://nvd3.org/ghpages/stackedArea.html)呢? –