如何编辑/自定义工具提示

时间:2015-01-24 23:00:11

标签: javascript highcharts

我正在尝试编辑工具提示,以便为图上的每个点创建唯一的名称。我正在尝试以下代码,但它无法正常工作。

这是小提琴:http://jsfiddle.net/57mqsv6g/1/

tooltip: 
{
    formatter: function() {
        return 'The value for <b>' + this.x + '</b> is <b>' + this.y + '</b>, in series '+ this.series.name;
    }
}

1 个答案:

答案 0 :(得分:0)

适合我:

http://jsfiddle.net/57mqsv6g/14/

$(function () {
    $('#container').highcharts({
        yAxis: {
            title: {
                text: "Apples"
            }
        },
        xAxis: {
            title: {
                text: "Protein"
            }
        },
        chart: {
            type: 'bubble',
            zoomType: 'xy'
        },

        title: {
            text: 'Highcharts Bubbles'
        },

        tooltip: {
            formatter: function() {
                return 'The value for <b>' + this.x + '</b> is <b>' + this.y + '</b>, in series '+ this.series.name;
            }
        },

        series: [{
            data: [[97, 36, 79], [94, 74, 60], [68, 76, 58], [64, 87, 56], [68, 27, 73], [74, 99, 42], [7, 93, 87], [51, 69, 40], [38, 23, 33], [57, 86, 31]]
        }, {
            data: [[25, 10, 87], [2, 75, 59], [11, 54, 8], [86, 55, 93], [5, 3, 58], [90, 63, 44], [91, 33, 17], [97, 3, 56], [15, 67, 48], [54, 25, 81]]
        }, {
            data: [[47, 47, 21], [20, 12, 4], [6, 76, 91], [38, 30, 60], [57, 98, 64], [61, 17, 80], [83, 60, 13], [67, 78, 75], [64, 12, 10], [30, 77, 82]]
        }]
    });
});

要在formatter函数中访问z,请使用this.point.z。这就是格式化程序中的外观:

formatter context