- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找使链接颜色与 d3 sankey 图表中的节点填充颜色相同的颜色。
我正在使用以下函数获取节点颜色
function getNodeColor(d){
console.log(d3.rgb(d.color).darker(2));
return d3.rgb(d.color).darker(2);
}
以下是我绘制链接文本颜色的代码
// add in the title for the nodes
node.append("text")
.attr("x", -6)
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("transform", null)
.text(function(d) { return d.name; })
.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start")
.style("stroke", getNodeColor);
上面的工作非常好,文本显示带有节点颜色的节点文本。当我尝试以相同的方式更改链接定义中的笔画值时,情况并非如此:
var link = svg.append("g").selectAll(".link")
.data(graph.links)
.enter().append("path")
.attr("class", "link")
.attr("d", path)
.style("stroke-width", function(d) { return Math.max(1, d.dy); })
.style("stroke", getNodeColor)
.sort(function(a, b) { return b.dy - a.dy; });
我是 d3 sankey 的新手,关注 http://bl.ocks.org/d3noob/c9b90689c1438f57d649
感谢帮助...
底线:我正在寻找使桑基图的链接/弦颜色与矩形填充颜色相同的...
最佳答案
您可以使用以下代码为图表中的链接使用源节点颜色。如果您更喜欢使用目标节点颜色,也可以使用 target.color
。
svg.selectAll(".link")
.style('stroke', function(d){
return d.source.color;
})
此代码需要放在设置节点颜色的代码之后。
关于d3.js 桑基链接颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36244075/
在默认的 Highcharts Sankey 图表中,您可以将鼠标悬停在各个路径上,这些路径会突出显示。 我希望能够悬停在节点上 - 例如下面示例中的加拿大 - 并在悬停在该节点上时突出显示所有红色路
我想知道一个特定的节点是否可以在类似states in hover(linkOpacity)的Click上高亮显示并在单击其他节点/系列时将其替换为之前的颜色。 简而言之,加载图表时,最上面的节点最初
(Plotly 4.10.0、Python 3.8.0、Ubuntu 20.04) 我正在使用 Plotly Sankeys,但自动放置看起来很麻烦(可惜我无法手动放置节点)。 import plot
如何根据过渡在 x 轴上显示动态文本。在我的第一个案例中,我得到两个转换(足球 -> 篮球和篮球 -> Gerard),因此我将显示两个标签,如下所示 但是当我们只得到一个转换时,如何处理 x 轴上的
我需要在桑基图之外显示标签,但我很难在外面显示。我尝试使用一些属性,如裁剪、溢出和对齐。尽管如此,它仍然不起作用。我需要在图表外部显示左侧和右侧的标签。 这是我的代码 Highcharts.chart
我是一名优秀的程序员,十分优秀!