如何在 sankey 中显示工具提示而不是求和
How to show tooltip instead of sum in sankey
如何显示与特定栏相关的工具提示。目前,我能够在栏之间显示工具提示。但是当我将鼠标悬停在足球或篮球或罗纳尔多或梅西而不是工具提示上时,总和就会出现。如何显示工具提示而不是总和。
基本上,这就是我想要的输出
当我将鼠标悬停在足球上时,我想要 1,2,4,5,6,7,8,9,11,12
同样,当我将鼠标悬停在篮球上时,我想要 11,12
Highcharts.chart('container', {
title: {
text: ''
},
xAxis: {
type: 'category'
},
series: [{
keys: ['from', 'to', 'weight', 'tooltip'],
data: [
['Football', 'Basketball', 20, [1,2] ],
['Football', 'Ronaldo', 3, [4,5,6] ],
//['Challenged', 'Terminated', 0 ],
['Football', 'Other', 1, [7,8,9,11,12] ],
['Basketball', 'Messi', 12, [] ],
//['Instituted', ' Terminated', 0 ],
['Basketball', 'Gerad', 6 , [] ],
['Basketball', ' Rooney', 2, [11,12] ],
],
type: 'sankey',
nodeFormat: function () {
var abc = [];
each(node.linksTo, function (link) { abc.push(link.tooltip) });
return abc;
},
}]
});
这里有两件事你需要做。
在 Bar 上为工具提示添加 nodeFormat,它默认为 {point.name}: <b>{point.sum}
这就是为什么你每次在 bar 上移动时都会看到 sum
pointFormat: '{point.fromNode.name} → {point.toNode.name} {point.tooltip}',
nodeFormat: '{point.name}: {point.name}'
我已经像上面那样在你的 fiddle 中更改了它 returns FoorBall:当我将鼠标悬停在第一个栏上时,FoorBall。
- 您需要编写nodeFormatter函数来解析每个点。这是定义节点格式的回调函数,默认为
undefined
.
您应该为 sankey
工具提示使用 nodeFormatter
函数,并根据需要创建一个字符串:
nodeFormatter: function() {
var result = '';
Highcharts.each(this.linksFrom, function(el) {
result += (el.tooltip && result ? ',' : '') + el.tooltip;
});
return result;
}
现场演示:https://jsfiddle.net/BlackLabel/mh0ye5a7/
API: https://api.highcharts.com/highcharts/series.sankey.tooltip.nodeFormatter
如何显示与特定栏相关的工具提示。目前,我能够在栏之间显示工具提示。但是当我将鼠标悬停在足球或篮球或罗纳尔多或梅西而不是工具提示上时,总和就会出现。如何显示工具提示而不是总和。 基本上,这就是我想要的输出
当我将鼠标悬停在足球上时,我想要 1,2,4,5,6,7,8,9,11,12 同样,当我将鼠标悬停在篮球上时,我想要 11,12
Highcharts.chart('container', {
title: {
text: ''
},
xAxis: {
type: 'category'
},
series: [{
keys: ['from', 'to', 'weight', 'tooltip'],
data: [
['Football', 'Basketball', 20, [1,2] ],
['Football', 'Ronaldo', 3, [4,5,6] ],
//['Challenged', 'Terminated', 0 ],
['Football', 'Other', 1, [7,8,9,11,12] ],
['Basketball', 'Messi', 12, [] ],
//['Instituted', ' Terminated', 0 ],
['Basketball', 'Gerad', 6 , [] ],
['Basketball', ' Rooney', 2, [11,12] ],
],
type: 'sankey',
nodeFormat: function () {
var abc = [];
each(node.linksTo, function (link) { abc.push(link.tooltip) });
return abc;
},
}]
});
这里有两件事你需要做。
在 Bar 上为工具提示添加 nodeFormat,它默认为
{point.name}: <b>{point.sum}
这就是为什么你每次在 bar 上移动时都会看到 sumpointFormat: '{point.fromNode.name} → {point.toNode.name} {point.tooltip}', nodeFormat: '{point.name}: {point.name}'
我已经像上面那样在你的 fiddle 中更改了它 returns FoorBall:当我将鼠标悬停在第一个栏上时,FoorBall。
- 您需要编写nodeFormatter函数来解析每个点。这是定义节点格式的回调函数,默认为
undefined
.
您应该为 sankey
工具提示使用 nodeFormatter
函数,并根据需要创建一个字符串:
nodeFormatter: function() {
var result = '';
Highcharts.each(this.linksFrom, function(el) {
result += (el.tooltip && result ? ',' : '') + el.tooltip;
});
return result;
}
现场演示:https://jsfiddle.net/BlackLabel/mh0ye5a7/
API: https://api.highcharts.com/highcharts/series.sankey.tooltip.nodeFormatter