[Sankey-diagram PowerBI自定义视觉,带有颜色节点和顺序

问题描述 投票:1回答:1

PowerBI的sankey图有很多可能性,但是正如您可以在github网站上阅读的那样,存在一些重要的限制。首先是不可能为节点着色。此外,也无法更改节点的顺序(源和目标)。

附带的是示例PowerBI file,其中显示了sankey。在该文件中指出了节点应具有的颜色以及节点的顺序。

最佳解决方案当然是使用PowerBI来指示颜色,如本示例中的链接所示。但是使用硬值指示代码本身中节点(名称)的颜色可能更容易,这也是一个不错的选择。节点的排序也是如此

我查看了d3的色阶函数,将其链接到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的其他用户。

javascript d3.js powerbi sankey-diagram powerbi-custom-visuals
1个回答
0
投票

看起来,如果您需要注入一些第三者的颜色值(无论是十六进制还是其他格式),可以在突出显示为“作弊”的代码中使用ColorHelper实例。可以在此处的powerbi文档中找到以下示例:https://github.com/microsoft/powerbi-visuals-utils-colorutils/blob/master/docs/api/colorUtils.md#calculatehighlightcolor

import ColorUtility = powerbi.extensibility.utils.color;

let yellow = "#FFFF00",
    yellowRGB = ColorUtility.parseColorString(yellow);

ColorUtility.calculateHighlightColor(yellowRGB, 0.8, 0.2);

// returns: '#CCCC00'

最终我认为这归结为这一辅助方法:

ColorUtility.parseColorString('<colorhex>')

我不知道确切地将其插入正在执行的操作的最佳方法,但是您可以尝试生成随机的十六进制颜色并将其插入以查看另一面的结果。

// thanks Paul Irish: https://www.paulirish.com/2009/random-hex-color-code-snippets/
let randcolor = '#'+Math.floor(Math.random()*16777215).toString(16)
// Then to replace the example code you had in your question...
nodeFillColor = this.colorHelper.parseColorString(randcolor)
nodeStrokeColor = this.colorHelper.getHighContrastColor("foreground", nodeFillColor);
© www.soinside.com 2019 - 2024. All rights reserved.