首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使自定义颜色和阈值与D3 RelationshipGraph一起工作

使自定义颜色和阈值与D3 RelationshipGraph一起工作
EN

Stack Overflow用户
提问于 2016-10-01 15:47:13
回答 1查看 151关注 0票数 1

基于这个例子:https://cdn.rawgit.com/hkelly93/d3-relationshipGraph/master/examples/index.html

D3应该允许我创建此图表,并为值更改颜色时定义颜色和阈值。该函数接受一些自定义设置:

代码语言:javascript
复制
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显示为绿色。以下是加载的数据(摘录):

代码语言:javascript
复制
[
{"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

从该文件中:

代码语言:javascript
复制
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/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-01 17:07:12

结果发现,这是模块本身的一个bug。我通知了作者,他修复了阈值排序的方式,因此它现在与相应的颜色相匹配。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39808540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档