2016-10-25 19 views
3

我的圖例不會出現在我的熱圖中。它說錯誤:「d3.legendColor不是一個函數」,但我不確定如何改變它的工作。由於legendColor D3圖例不出現

全圖和全碼: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); 

回答

1

如果您正在使用蘇茜路的D3傳奇http://d3-legend.susielu.com/),你必須引用它:

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

啊,是的,這是它所需要的,非常感謝你! – J64