基于这个例子:https://cdn.rawgit.com/hkelly93/d3-relationshipGraph/master/examples/index.html
D3应该允许我创建此图表,并为值更改颜色时定义颜色和阈值。该函数接受一些自定义设置:
var graph = d3.select('#graph').relationshipGraph({
maxChildCount: 10,
valueKeyName: 'Story title',
thresholds: [6, 8, 10],
colors: ['red', 'yellow', 'green'],
showTooltips: true
})但是,当我将数据加载到所有三个范围时,我不会得到三种颜色的图形。我希望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/
发布于 2016-10-01 17:07:12
结果发现,这是模块本身的一个bug。我通知了作者,他修复了阈值排序的方式,因此它现在与相应的颜色相匹配。
https://stackoverflow.com/questions/39808540
复制相似问题