2016-10-01 33 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

他在我的请求的几分钟之内推动了错误修复!惊人的开源客户服务! –