Display array values as unique tooltip in highchar

2019-09-20 02:23发布

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..

2条回答
Rolldiameter
2楼-- · 2019-09-20 02:31

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];
    }
},
查看更多
可以哭但决不认输i
3楼-- · 2019-09-20 02:52

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/

查看更多
登录 后发表回答