Trouble getting unique tooltip based on X axis values in highcharts line graph

别来无恙 提交于 2019-12-11 12:29:12

问题


I'm trying to make a graph in which points having different x axis values have different tooltip .The 1st two points of a series have the same tooltip even though their x axis values are different.i.e points under the month of jan should have "11st comment" tooltip,points under Feb should have "22nd comment" tooltip so on and so forth even if their x axis values are same but not y axis values..

The current computational logic is that the tooltip depends upon the y axis values.As long as y axis values are changing the tool tip changes accordingly.This happens because of the statement"this.y" in the below code..

The problem with this logic is that as long as y axis values are distinct the tooltip works properly,the moment 2 consecutive points of a series have same y axis values the tooltip does not change when their x values are different...

To make the tooltip change acoording to x axis values I am replacing "this.y" with "this.x" but the desired change is not happening.Can you please tell me how to make that change?

The tool tip code..

       tooltip: {
       formatter: function () {
        var serieI = this.series.index;
      var index = dataValues.indexOf(this.y);
     var index1= dataValues2.indexOf(this.y);
      debugger;
        var comment = "";
        if (serieI == 0) {
            comment = $("#ppForm.textarea:eq(" + (index) + ")").val();
        } else {
           //comment = "second serie matched!";
            comment = $("#ppForm.textarea:eq(" + (index1) + ")").val();
        }
        /*return ''+ this.x +
            '</b> is <b>' + this.y + '</b> -->' + comment;*/
        return '-->'+comment;
    }
}

The js fiddle is... http://jsfiddle.net/RbenU/25/


回答1:


Instead of using index for dataValues use index for categories, this way: http://jsfiddle.net/RbenU/39/

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


来源:https://stackoverflow.com/questions/16538725/trouble-getting-unique-tooltip-based-on-x-axis-values-in-highcharts-line-graph

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