Unable To Display Legend For A Quantile Scale In D3
I am trying to display a legend for a heat map I have created, but am unable to do that. Here is my HTML Heat Map Data Visualization<
Solution 1:
I have modified your pen like this:
// Save the legend svg in a variable // also changed the translate in order to keep the legend within the svg // and place it on the right side just for the example's sakevar legendSvg = svg.append('g')
.attr('class', 'legend')
.attr("transform","translate("+ (width - 40) + ",20)")
// Define the legend as you didvar legend = d3.legendColor()
.useClass(true)
.shape('rect')
.orient('vertical')
.title('Temperature Variance')
.shapeWidth(legendElementWidth)
.scale(colorScale);
// And then call legend on the legendSvg not on svg itself
legendSvg.call(legend);
Hope this helps, good luck!
Post a Comment for "Unable To Display Legend For A Quantile Scale In D3"