简体   繁体   English

自己的工具提示高图

[英]Own Tooltip highchart

I have an array. 我有一个阵列。 Var myArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']; Var myArray = ['a','b','c','d','e','f','g','h','i'];

I want to change the default tooltip with my array. 我想用我的数组更改默认工具提示。 Where value of first tooltip from bar is 'a', second is 'b' and forth until 'i'. 来自bar的第一个工具提示的值是'a',第二个是'b',直到'i'。

like this pic: 像这张照片: 在此输入图像描述

how i can do it? 我怎么能这样做?

this is my code 这是我的代码

<script type="text/javascript">
$(function () {
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column'
            },
            title: {
                text: 'Monthly Average Rainfall'
            },
            subtitle: {
                text: 'Source: WorldClimate.com'
            },
            xAxis: {
                categories: [
                    'Jan',
                    'Feb',
                    'Mar'
                ]
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Rainfall (mm)'
                }
            },
            legend: {
                layout: 'vertical',
                backgroundColor: '#FFFFFF',
                align: 'left',
                verticalAlign: 'top',
                x: 100,
                y: 70,
                floating: true,
                shadow: true
            },
            tooltip: {
                formatter: function() {
                    var myArray = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'];
                    var i =0;
                    i++;
                    return ''+myArray[i] ;


                }
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
                series: [{
                name: 'Tokyo',
                data: [49.9, 71.5, 106.4]

            }, {
                name: 'New York',
                data: [83.6, 78.8, 98.5]

            }, {
                name: 'London',
                data: [48.9, 38.8, 39.3]

            }, {
                name: 'Berlin',
                data: [42.4, 33.2, 34.5]

            }]
        });
    });

});
        </script>

First of all, this is obviously not that clever: 首先,这显然不是那么聪明:

var i =0;
i++;

As you could see when debugging, you have access to the key (and more). 正如您在调试时看到的那样,您可以访问密钥(以及更多)。 I would make an associative array as such: 我会像这样制作一个关联数组:

var myTooltips = { "Jan": A, "Feb": B, "Mar": C } // Etc

// Other code
(function($){ // encapsulate jQuery
var chart;

And

formatter: function() {
    return myTooltips[ this.key ];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM