以完全相同的时间显示两个点的工具提示

时间:2015-05-10 16:30:42

标签: highcharts highstock

我需要在时间轴上显示可能包含两个不同点且时间完全相同的图表。在这种情况下,Highcharts仅显示第一个点的工具提示。是否可以让Highcharts为每个点显示工具提示?

http://jsfiddle.net/Lod5jsz8/1/

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'spline'
        },
        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: {
                month: '%e. %b',
                year: '%b'
            },
            title: {
                text: 'Date'
            }
        },
        yAxis: {
            title: {
                text: 'Snow depth (m)'
            },
            min: 0
        },
        tooltip: {
            headerFormat: '<b>{series.name}</b><br>',
            pointFormat: '{point.x:%e. %b}: {point.y:.2f} m',
            shared: true
        },

        plotOptions: {
            spline: {
                marker: {
                    enabled: true
                }
            }
        },

        series: [{
            name: 'Winter 2007-2008',            
            data: [
                [Date.UTC(1970,  9, 27), 0   ],
                [Date.UTC(1970, 10, 10), 0.6 ],
                [Date.UTC(1970, 10, 18), 0.7 ],
                [Date.UTC(1970, 11,  2), 0.8 ],
                [Date.UTC(1970, 11,  2), 0.2 ],
                [Date.UTC(1970, 11,  9), 0.6 ]                
            ]
        }]
    });
});

1 个答案:

答案 0 :(得分:1)

Defaulty共享参数在系列之间工作,而不是同一系列中的点。因此,您可以使用formatter和循环来查找具有相同x的点。

var arr = ['apples', 'bananas', 'oranges', 'strawberries'];

function check(arr, fruit) {
    return arr.some(function (el) {
        return el.indexOf(fruit) > -1;
    });
}

if (check(arr, 'oranges') {
    // do stuff if true
}

示例:http://jsfiddle.net/Lod5jsz8/4/