问题
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