highcharts 桑基图中的不同节点工具提示
Different node tooltips in highcharts sankey diagram
在 Highcharts sankey 图中,我想用工具提示标记节点。左侧(发送方节点)的标记应与右侧(接收方节点)不同。
示例:
左节点:"CVP (Origin Party Votes): 6000"
右节点:"CVP (Receiver Party Votes): 5000"
我尝试使用 nodeFormatter 格式化函数,但失败了。
jsfiddle 在这里:https://jsfiddle.net/martindfurrer/ah175o8e/
tooltip: {
nodeFormatter:
function() {
if (this.point.fromNode.name != null) {
return (point.name +'(Origin Party Votes): '+point.sum);
}
else if (this.point.toNode.name != null) {
return (point.name +'(Receiver Party Votes): '+point.sum);
};
}
}
可以用column
来识别左右节点(fiddle):
tooltip: {
nodeFormatter: function() {
if (this.column === 0) {
return (this.name + ' (Origin Party Votes): ' + this.sum);
} else if (this.column === 1) {
return (this.name + ' (Receiver Party Votes): ' + this.sum);
}
}
}
如果将 console.log(this)
作为 nodeFormatter
函数的第一行,您可以探索节点上的可用属性。
在 Highcharts sankey 图中,我想用工具提示标记节点。左侧(发送方节点)的标记应与右侧(接收方节点)不同。
示例:
左节点:"CVP (Origin Party Votes): 6000"
右节点:"CVP (Receiver Party Votes): 5000"
我尝试使用 nodeFormatter 格式化函数,但失败了。 jsfiddle 在这里:https://jsfiddle.net/martindfurrer/ah175o8e/
tooltip: {
nodeFormatter:
function() {
if (this.point.fromNode.name != null) {
return (point.name +'(Origin Party Votes): '+point.sum);
}
else if (this.point.toNode.name != null) {
return (point.name +'(Receiver Party Votes): '+point.sum);
};
}
}
可以用column
来识别左右节点(fiddle):
tooltip: {
nodeFormatter: function() {
if (this.column === 0) {
return (this.name + ' (Origin Party Votes): ' + this.sum);
} else if (this.column === 1) {
return (this.name + ' (Receiver Party Votes): ' + this.sum);
}
}
}
如果将 console.log(this)
作为 nodeFormatter
函数的第一行,您可以探索节点上的可用属性。