我的图例不会出现在我的热图中。它显示错误:“d3.legendColor 不是函数”,但我不确定如何更改它才能正常工作。
完整图表和完整代码:http://codepen.io/jeffm64/pen/gwQAyb
代码
var colorScale = d3.scaleQuantile()
.domain([minVariance + baseTemp, maxVariance + baseTemp])
.range(colors);
//creates the legend for the heatmap
d3.select("svg")
.append("g")
.attr("class", "legendQuant")
.attr("transform", "translate(20,20)");
var legend = d3.legendColor()
.labelFormat(d3.format(".2f"))
.useClass(true)
.scale(colorScale);
svg.select(".legendQuant")
.call(legend);
最佳答案
如果您使用的是 Susie Lu 的 d3 Legend ( http://d3-legend.susielu.com/ ),则必须引用它:
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-legend/2.13.0/d3-legend.js"></script>
关于javascript - 由于 legendColor,D3 图例未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40246490/