PowerBI 的 sankey 图有很多可能性,但正如您可以在 github 网站上阅读的那样,存在一些重要的限制。首先是无法为节点着色。此外,也无法更改节点(源和目标)的顺序。
附件是一个示例 PowerBI文件,其中显示了一个 sankey。在这个文件中指出了节点应该有哪些颜色以及节点的顺序应该是什么。
最好的解决方案当然是使用 PowerBI 来指示颜色,如本示例中的链接。但可能更容易在代码本身中用硬值指示节点(名称)的颜色,这也是一个不错的选择。同样适用于节点的排序
我查看了 d3 的 colorscale 函数将其链接到 fillcolor。但我收到一条错误消息,指出字符串值无法链接到色标。
可以在此处找到包含代码的 Github 页面: https ://github.com/microsoft/powerbi-visuals-sankey
我认为这行代码应该改变:
nodeFillColor = this.colorHelper.isHighContrast ? this.colorHelper.getThemeColor() : this.colorPalette.getColor(index.toString()).value;
console.log(nodeFillColor);
nodeStrokeColor = this.colorHelper.getHighContrastColor("foreground", nodeFillColor);
颜色现在基于主题颜色。希望可以将节点(名称)链接到颜色而不是主题。
希望您能帮助我和其他 Sankey 用户。