2014-02-17 41 views
0

覆蓋程度我有一系列已創建這樣地平線圖表:一個地平線實例

d3.select("body") 
    .selectAll(".horizon") 
    .data(metrics) 
    .enter() 
    .append("div") 
    .attr("class", "horizon") 
    .attr("id", function(d){return d.toString();}) 
    .call(context.horizon().height(['75'])); 

其中metricsmetric是對象的數組。

我想重新定義extent那些horizon對象一個

我試過呼籲一個圖形的extent功能,但我不知道如果我打電話給它,甚至選擇它,正確:

d3.select("#id-attribute") 
    .call(context.horizon().extent(function(d,i){return([0,1000]);})); 

這個排序似乎工作,但圖表顯示被搞砸了,在圖表下面增加了空白,圖表的運動沒有考慮到這一點,並且保持圖表頂部不動。我懷疑它在某些方面,由於它是在extent對象的新實例,所以我想這:

d3.select("#id-attribute") 
    .call(extent(function(d,i){return([0,1000]);})); 

但產生:「ReferenceError: extent is not defined」。

我試圖重新定義metricextent功能,有效:

metrics[3].extent = function(d,i) {return([0,100]);}; 

但使圖形是空白的(雖然鼠標懸停在讀出數字顯示),並導致其讀出和當鼠標沒有懸停在任何圖表上時,出現在其下面的圖形的讀數爲空白。

我真的沒有理解這些東西是如何融合在一起的,我也不是很瞭解JavaScript,所以我不確定我的錯誤在哪裏。我完全超出了我的深度。 任何提示將不勝感激。

回答

1

您是否需要重新定義在生成視界的初始調用之後的範圍?

如果沒有,嘗試這樣的事:

d3.select("body") 
    .selectAll(".horizon") 
    .data(metrics) 
    .enter() 
    .append("div") 
    .attr("class", "horizon") 
    .attr("id", function(d){return d.toString();}) 
    .call(context.horizon() 
      .height(['75']) 
      .extent(function(d,i){ //use this function to change extents 
        if (d.toString() == 'Whatever the name is'){ 
         return [0,1000]; 
        } else { 
         return [ <default min>, <default max>] 
        } 
       }) 
) 

您可以設定自己的默認範圍,或使用像d3.min()/ d3.max()函數來得到該值視野。你只需要返回一個包含兩個元素的數組。

+0

一個絕妙的想法。 – wfaulk

相關問題