【问题标题】:Show multiple Tooltips in highcharts on overlapping points在重叠点的高图中显示多个工具提示
【发布时间】:2019-08-06 03:38:03
【问题描述】:

仅当多个系列点重叠时才需要在高图中显示多个工具提示。

我可以通过以下链接实现相同的功能。 https://stackoverflow.com/questions/28918567/showing-multiple-tooltips-in-highcharts-simultaneously

但我在这里面临的唯一问题是在将鼠标悬停在单个系列上时总是显示重复的工具提示(与上面的示例不同,这里我使用时间序列图,以便线点是连续的)。

请帮我解决这个问题。


嗨@ppotaczek, 这是我在这个小提琴中面临的问题 - brfLdv7o

显示蓝色工具提示,即使我悬停在黄色系列线。 请检查随附的屏幕截图。

【问题讨论】:

    标签: javascript highcharts


    【解决方案1】:

    您可以使用tooltip.split 属性来呈现多个工具提示,并在工具提示refresh 方法包装中隐藏不需要的工具提示:

    (function(H) {
        H.wrap(H.Tooltip.prototype, 'refresh', function(proceed, points) {
            var split = false,
                labels;
    
            proceed.apply(this, Array.prototype.slice.call(arguments, 1));
    
            labels = this.label.element.children;
    
            for (var i = 1; i < points.length; i++) {
                if (
                    points[i - 1].x === points[i].x &&
                    points[i - 1].y === points[i].y
                ) {
                    split = true;
                    break;
                }
            }
    
            if (!split) {
                points.forEach(function(p) {
                    if (p.hoveredPoint) {
                        labels[p.series.index].setAttribute('opacity', 1);
                        p.hoveredPoint = false;
                    } else {
                        labels[p.series.index].setAttribute('opacity', 0);
                        p.setState('');
                    }
                }, this)
            } else {
                points.forEach(function(p) {
                    labels[p.series.index].setAttribute('opacity', 1);
                })
            }
        });
    }(Highcharts));
    
    Highcharts.chart('container', {
        plotOptions: {
            series: {
                point: {
                    events: {
                        mouseOver: function(event) {
                            this.hoveredPoint = true;
                        }
                    }
                },
            }
        },
    
        ...
    });
    

    现场演示: http://jsfiddle.net/BlackLabel/ymr1xbnh/

    文档: https://www.highcharts.com/docs/extending-highcharts

    API 参考:

    https://api.highcharts.com/highcharts/tooltip.split

    https://api.highcharts.com/highcharts/series.line.point.events.mouseOver

    【讨论】:

    • 我正在使用 highcharts-angular v2.3.1。试过你的代码不能正常工作。抱歉,由于我在银行领域工作,因此我无法共享代码库。
    • 找出根本原因。您的方法不适用于较大的数据,即具有连续点的时间序列。
    • 请查看此小提琴以获取多个系列的示例数据jsfiddle.net/61s2a0r9
    • 嗨@Sarun UK,它似乎按预期工作。点必须具有相同的 x 和 y 值:jsfiddle.net/BlackLabel/q1j23emt
    • 嗨@Sarun UK,很抱歉造成误解。标签的顺序是错误的。请检查更正后的示例:jsfiddle.net/BlackLabel/qc2Ldry8
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多