首页 > 解决方案 > Highcharts Sankey Charts中链接和节点的不同工具提示文本

问题描述

我有一个 Highcharts sankey 图,并且希望将鼠标悬停在节点上时的工具提示文本与链接文本不同。当我只对工具提示使用 formatter() 方法时,我得到了我想查看的链接文本,而不是节点。除了 formatter() 方法之外,我还尝试使用 nodeFormatter() 方法来代替它,但这完全覆盖了我试图对链接执行的操作。

    var chart = Highcharts.chart('chart_container', {

        title: {
            text: null
        },
        plotOptions: {
            sankey: {
                nodeWidth:100
            }
        },
        tooltip:{
            enabled: true,
            formatter: function() {
             //Return stuff here
            }
        },
        series: [
            {
                type: 'sankey',
                name: null,
                data:   migrationData.seriesData,
                nodes:  migrationData.nodes,
                dataLabels: {
                  enabled: true,
                },
            },

        ],
        allowPointSelect: true,
        enableMouseTracking: false,
        tooltip: {
        nodeFormatter: function() {
            //Just overwrites tooltip text for non-nodes as well
        }
    }
  });

知道如何让节点说出“类别:数字”之类的内容以及在工具提示中包含更复杂细节的链接吗?

标签: highchartssankey-diagram

解决方案


您可以使用pointFormatternodeFormatter功能:

series: [{
    ...,
    tooltip: {
        nodeFormatter: function() {
            return 'some text for node'
        },
        pointFormatter: function() {
            return 'some text for link'
        }
    }
}]

现场演示: https ://jsfiddle.net/BlackLabel/romtnqx5/

API参考:

https://api.highcharts.com/highcharts/series.sankey.tooltip.pointFormatter

https://api.highcharts.com/highcharts/series.sankey.tooltip.nodeFormatter


推荐阅读