Display array values as unique tooltip in highcharts

馋奶兔 提交于 2019-12-13 23:15:32

问题


I am trying to display values of an array as tooltip in highcharts line graph.I am currently using values entered from a textbox as tooltip but trying to display array values as tooltip..the js fiddle is given here http://jsfiddle.net/RbenU/75/

the tooltip code i am using is..

       tooltip: {
        formatter: function () {
            var serieI = this.series.index;
            var index = categories.indexOf(this.x);
            var comment = $("input:eq(" + (index) + ")").val();
            return '-->'+comment;
        }
    },

I want to display values of array n as tool-tip i.e. n[0] element for JAN, n[1] element for Feb so on and so forth..Points falling under the same month will have same tooltip..


回答1:


Just use the index you are getting from the categories array to get that value from n:

tooltip: {
    formatter: function () {
        var index = categories.indexOf(this.x);
        return n[index];
    }
},



回答2:


declare an array:

 var myComments=["First input","second comment","another comment","last comment"];

instead of the line:

 var comment = $("input:eq(" + (index) + ")").val();

write the line:

 var comment = myComments[index];

and it should work...

jsfiddle example: http://jsfiddle.net/yoav_barnea/2meEg/



来源:https://stackoverflow.com/questions/17019897/display-array-values-as-unique-tooltip-in-highcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!