Javascript D3图例颜色始终保持黑色
我一直在使用这个图书馆。现在我已经设置了比例和颜色比例,我得到了预期的比例,但是整个比例的颜色是黑色的Javascript D3图例颜色始终保持黑色,javascript,d3.js,Javascript,D3.js,我一直在使用这个图书馆。现在我已经设置了比例和颜色比例,我得到了预期的比例,但是整个比例的颜色是黑色的 问题是您使用的是useClass(true)。根据报告: 如果将useClass设置为true,则它会将比例的输出作为类应用于形状,而不是填充或笔划 解决方案:只需将其移除: var legend = d3.legendColor() .labelFormat(d3.format(".2f")) .labels(d3.legendHelpers.thresholdLabels) .
问题是您使用的是
useClass(true)
。根据报告:
如果将useClass设置为true,则它会将比例的输出作为类应用于形状,而不是填充或笔划
解决方案:只需将其移除:
var legend = d3.legendColor()
.labelFormat(d3.format(".2f"))
.labels(d3.legendHelpers.thresholdLabels)
.title("Color Legend")
.scale(color)
以下是更改后的代码:
var svg=d3.选择(“svg”);
svg.append(“g”)
.attr(“类”、“图例”)
.attr(“转换”、“翻译(20,20)”);
var color=d3.scaleThreshold()
.domain([0,0.4,0.8,1.2,1.6,2.0,2.4,2.8]).range([c6dbef'、'a1c8e4'、'7ab4da'、'5692c5'、'316aac'、'08488a'、'062c58'、'03132b');
var legend=d3.legendColor()
.labelFormat(d3.format(“.2f”))
.标签(d3.legendHelpers.thresholdLabels)
.标题(“颜色图例”)
.刻度(颜色)
选择(“图例”)
.通话(图例)代码>
在指向整个html的示例链接中,这些都是彩色的-感谢您解决了这个问题。它工作得很好。
var legend = d3.legendColor()
.labelFormat(d3.format(".2f"))
.labels(d3.legendHelpers.thresholdLabels)
.title("Color Legend")
.scale(color)