我想分割一些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