J64 J64 - 1 month ago 13
Javascript Question

D3 legend not appearing due to legendColor

My legend won't appear for my heatmap. It says the error: "d3.legendColor is not a function" but I am unsure of how to change it to work.

full chart and full code: http://codepen.io/jeffm64/pen/gwQAyb

The code

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);

Answer

If you are using Susie Lu's d3 Legend (http://d3-legend.susielu.com/), you'll have to reference it:

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-legend/2.13.0/d3-legend.js"></script>
Comments