Google图表API:在Sankey图表中设置节点标签的值 [英] Google chart API: Set values of node labels in Sankey diagram

查看:98
本文介绍了Google图表API:在Sankey图表中设置节点标签的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的Sankey图,该图显示两组节点之间的流,并希望两组节点具有相同的名称.但是,这是不允许的(它会引发行中发现循环"错误),因此我在第二组节点的名称中添加了"2",如下所示:

I am trying to create a simple Sankey diagram showing flows between two sets of nodes, and would like the two sets to have the same names. However, this isn't allowed (it brings up a "Cycle found in rows" error), so I add "2" to the names of the nodes in the second set, like so:

        function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'From');
        data.addColumn('string', 'To');
        data.addColumn('number');
        data.addRows([
            ['foo', 'foo2', 6],
            ['bar', 'bar2', 4],
            ['foo', 'bar2', 6],
            ['bar', 'foo2', 4]
        ]);

        var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
        chart.draw(data);
      }

但是,我不希望节点标签说"foo2"和"bar2"-我只希望它们说"foo"和"bar".在某些情况下,您可以在Google Visualization API中使用{v:'foo2',f:'foo'}和{v:'bar2',f:'bar'}解决此问题,但这在这里不起作用.有什么办法可以做到吗?

However, I don't want the node labels to say "foo2" and "bar2" -- I just want them to say "foo" and "bar". In some cases in Google Visualization API you can solve this problem with {v: 'foo2', f: 'foo'} and {v: 'bar2', f: 'bar'}, but that doesn't work here. Is there any way I can do this?

推荐答案

尝试在末尾使用空格...

try using a space at the end...

['foo', 'foo ', 6],
['bar', 'bar ', 4],
['foo', 'bar ', 6],
['bar', 'foo ', 4]

请参阅以下工作片段...

see following working snippet...

google.charts.load('current', {
  packages: ['sankey']
}).then(function () {
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'From');
  data.addColumn('string', 'To');
  data.addColumn('number');
  data.addRows([
    ['foo', 'foo ', 6],
    ['bar', 'bar ', 4],
    ['foo', 'bar ', 6],
    ['bar', 'foo ', 4]
  ]);

  var chart = new google.visualization.Sankey(document.getElementById('sankey_basic'));
  chart.draw(data);
});

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

这篇关于Google图表API:在Sankey图表中设置节点标签的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆