我想分割一些D3圖Y軸垂直彩色線。您可以在下面的是當前外觀的圖片中看到,如何它應該看起來像:拆分D3圖Y軸垂直彩色線
什麼我試過到目前爲止被設置背景顏色爲克元太行止跌不會顯示在該特定區域,但它不起作用;我無法設置與background-color: gray;
背景顏色。
要讓HTML標記的一個更好的主意,你可以在下面的彩色線條體表示爲D3 foreignObjects
和他們下位於的文本值的圖片中看到。
有沒有人對如何讓這些彩色線條分裂的想法?
更新
仍然無法在我的情況下工作。我試圖先渲染彩色線條,然後再渲染文本值。這裏是我的代碼:
//Add colored lines
this.graph.append("foreignObject")
.attr("id", "legendBackground" + segmentId)
.attr("class", "legendBackground")
.attr("height", this.graphHeight)
.attr("width", "2")
.attr("y", 0)
.attr('x', xOffset + 11)
.style('background-color', (d) => this.colors(segmentId));
this.updateLegend();
//Add text values
var yScale = this.getYScale(domain);
var yAxis = d3.svg.axis()
.scale(yScale)
.tickSize(value)
.tickFormat(d3.format(".1f"))
.tickPadding(this.isSmallScreen ? 6 : 12)
.orient("left");
/** If there is already an xAxis then update this one, do not redraw from scratch */
if (!this.graph.select(".y.axis" + (secondary ? "2" : "")).empty()) {
var t0 = this.graph.select(".y.axis" + (secondary ? "2" : ""))
.attr("transform", "translate(" + (secondary ? (this.primaryAxis.width + this.padding.left + this.secondaryAxis.width + this.axisSpacing) : (this.primaryAxis.width + this.padding.left)) + ",0)")
.transition()
.call(yAxis);
} else {
var t0 = this.graph.insert("svg:g",":first-child")
.attr("class", secondary ? "y axis2" : "y axis")
.attr("transform", "translate(" + (secondary ? (this.primaryAxis.width + this.padding.left + this.secondaryAxis.width + this.axisSpacing) : (this.primaryAxis.width + this.padding.left)) + ",0)")
.transition()
.call(yAxis);
}
請注意我最新的問題更新。 – user2649344
此時,調試代碼的唯一方法是如果您提供[MCVE](http://stackoverflow.com/help/mcve)。 –
我修復了這個問題。這是d3版本的東西。謝謝您的回答。 – user2649344