Google Charts Sankey

编程入门 行业动态 更新时间:2024-10-11 05:25:16
本文介绍了Google Charts Sankey - 节点文字样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法可以在Google的Sankey图中用风格角色更改目标节点文本的颜色?目前我有这样的数据设置: $ p $ [源,目标,标签,样式] [A,B, Test Label,#ffffff]

我可以改变节点的颜色和链接但不是文字。

d3在这一点上对我来说不是一种选择,整个想法是让节点动起来,使它们在它的位置上一个接一个地出现 - 因此试图改变样式并重新绘制图表。增长表不工作,因为节点改变位置。任何想法?

解决方案

使用标准选项找不到样式个别节点文本 / p>

但是可以手动设置颜色,在绘制图表后 p

通常,图表的'ready'事件可用于知道图表何时完成绘图,但是,图表将恢复为默认的节点文本样式 em>在每一个交互事件中, 如'onmouseover','onmouseout', &安培;取而代之的是,使用突变观察者来更改节点文本,然后选择'select'

任何交互性

请参阅以下工作片段,它将颜色映射到每个节点文本 ...

...

google.charts.load('current',{'packages':['sankey']}); google。 charts.setOnLoadCallback(drawChart);函数drawChart(){var data = new google.visualization.DataTable(); data.addColumn('string','From'); data.addColumn('string','To'); data.addColumn('number','Weight'); data.addRows([['A','X',5],['A','Y',7],['A','Z',6],['B','X', 2],['B','Y',9],['B','Z',4]]); var options = {width:600}; var colorMap = {'A':'cyan','X':'洋红','Y':'yellow','Z':'lime','B':'violet'}; var chartDiv = document.getElementById('sankey_basic'); var chart = new google.visualization.Sankey(chartDiv); var observer = new MutationObserver(function(mutations){mutations.forEach(function(mutation){mutation.addedNodes.forEach(function(node){if(node.tagName ==='text'){node.setAttribute('font node.setAttribute('fill',colorMap [node.innerHTML]);}});});}); observer.observe(chartDiv,{childList:true,subtree:true}); chart.draw(data,options);}

< script>< / div>< / script> / pre>

Is there a way to change the color of the target node text with style role in Google's Sankey diagram? Currently I have data setup like this:

[Source, Target, Label, Style] [A,B,"Test Label", "#ffffff"]

I am able to change the color of the node and links but not the text.

d3 is not an option for me at this point and the whole idea is to animate the nodes to appear one after the another at its place - hence trying to change the style and re-draw the diagram. Growing the table is not working because the nodes change location. Any ideas?

解决方案

couldn't find a way to style individual Node text using standard options

but the color can be set manually, after the chart is drawn

normally, the chart's 'ready' event can be used to know when the chart has finished drawing, however, the chart will revert back to the default Node text style on every interactive event, such as 'onmouseover', 'onmouseout', & 'select'

instead, use a mutation observer to change the Node text on any interactivity

see following working snippet, which maps a color to each Node text...

google.charts.load('current', {'packages':['sankey']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('string', 'From'); data.addColumn('string', 'To'); data.addColumn('number', 'Weight'); data.addRows([ ['A', 'X', 5], ['A', 'Y', 7], ['A', 'Z', 6], ['B', 'X', 2], ['B', 'Y', 9], ['B', 'Z', 4] ]); var options = { width: 600 }; var colorMap = { 'A': 'cyan', 'X': 'magenta', 'Y': 'yellow', 'Z': 'lime', 'B': 'violet' }; var chartDiv = document.getElementById('sankey_basic'); var chart = new google.visualization.Sankey(chartDiv); var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { mutation.addedNodes.forEach(function (node) { if (node.tagName === 'text') { node.setAttribute('font-size', '20'); node.setAttribute('fill', colorMap[node.innerHTML]); } }); }); }); observer.observe(chartDiv, { childList: true, subtree: true }); chart.draw(data, options); }

<script src="www.gstatic/charts/loader.js"></script> <div id="sankey_basic"></div>

更多推荐

Google Charts Sankey

本文发布于:2023-10-19 18:50:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508440.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Google   Charts   Sankey

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!