【问题标题】:How to display same data points in a same series in highcharts?如何在highcharts中显示同一系列中的相同数据点?
【发布时间】:2021-01-07 06:47:04
【问题描述】:

如何在highcharts中显示同一系列的相同数据点?

请参考以下示例

https://jsfiddle.net/skoormala/1wq603rs/3/

series: [{
    name: 'Property',
    data: [{"name":"Property 1", "x":1,"y":2}, 
     **{"name":"Property 2", "x":2,"y":5}**,
     **{"name":"Property 5", "x":2,"y":5},**
     {"name":"Property 3", "x":3,"y":6},
      {"name":"Property 4", "x":4,"y":8}]
}]

在上述系列中,属性 2 和属性 5 具有相同的坐标,请告知如何在鼠标悬停时在工具提示中显示它们

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    tooltip.shared 属性仅适用于不同系列的点,对于单个系列您可以使用pointFormatter 函数根据您的要求构建工具提示,例如:

        tooltip: {
            pointFormatter: function() {
                const x = this.x,
                    y = this.y;
                const points = this.series.points.filter(p => p.x === x && p.y === y);
                const pointNames = points.reduce(
                    (result, point) => ((result ? result + ', ' : '') + point.name),
                    ''
                );
    
                return pointNames + '<br/>' + 'x: ' + x + '<br/>y: ' + y
            }
        }
    

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

    API 参考: https://api.highcharts.com/highcharts/tooltip.pointFormatter

    【讨论】:

    猜你喜欢
    • 2019-05-16
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    相关资源
    最近更新 更多