2016-10-01 37 views
1

基於這個例子的工作: https://cdn.rawgit.com/hkelly93/d3-relationshipGraph/master/examples/index.html獲取自定義顏色和閾值與D3 RelationshipGraph

D3應該讓我創建這個圖表和定義顏色和閾值,當值改變顏色。該函數接受一些自定義設置:

var graph = d3.select('#graph').relationshipGraph({ 
    maxChildCount: 10, 
    valueKeyName: 'Story title', 
    thresholds: [6, 8, 10], 
    colors: ['red', 'yellow', 'green'], 
    showTooltips: true 
}) 

但我沒有得到有三種顏色的曲線,當我加載數據擬合到所有3個範圍。我想0-6呈現紅色,7-8呈現黃色,9-10呈現綠色。下面是加載的數據(節選):

[ 
{"parent": "2012-October", "organization": "WEWASAFO", "value": 10, "Story title": "NUTRITION"}, 
{"parent": "2012-April", "organization": "Jitegemee", "value": 5, "Story title": "Life in the street"}, 
{"parent": "2011-May", "organization": "KENYA YOUTH BUSINESS TRUST (KYBT)", "value": 2, "Story title": "BUSINESS"} 
] 

其他一切解析正確,但在同一圖表上結合自定義顏色的自定義閾值。任何一個人都可以工作,但不能一起工作。

源回購是在這裏與一些文檔: https://github.com/hkelly93/d3-relationshipgraph

從該文檔:

thresholds: [100, 200, 300], // The thresholds for the color changes. If the values are strings, the colors are determined by the value of the child being equal to the threshold. If the thresholds are numbers, the color is determined by the value being less than the threshold. 
colors: ['red', 'green', 'blue'], // The custom color set to use for the child blocks. These can be color names, HEX values, or RGBA values. 

它沒有明確說明,孩子的顏色對應於閾值出現的順序。在這個例子中,所有塊都顯示爲紅色。

我這裏測試的代碼:https://jsfiddle.net/cgrx3e9m/

回答

1

這竟然是模塊本身中的錯誤。我通知了作者,他修復了它對門檻進行排序的方式,以便與相應的顏色匹配。

+1

他在我的請求的幾分鐘之內推動了錯誤修復!驚人的開源客戶服務! –