Home Forums Chart Support No Way to Sort Tooltip?

No Way to Sort Tooltip?

Viewing 3 posts - 1 through 3 (of 3 total)
  • #36692

    Hello!

    Just started implementing ChartJS and I really like it. Trying to find a way to sort the tooltip so that it always shows in the correct order based on the values. It’s kind of confusing to be moving the mouse across the chart and the labels and values stay the in the same position even though they are changing in the chart below. So far I’ve had no luck finding a setting or method to do this. Is it possible? If not, will it ever be?

    #36695

    @glowery,

    CanvasJS chart supports sorting the tooltip based on y-values with the help of contentFormatter. Please find the code-snippet below –

    toolTip: {
      shared: true,
        contentFormatter: function (e) {
          var content = "";
    
          e.entries.sort(function(a,b) {
            return b.dataPoint.y - a.dataPoint.y;
          });
    
          content	+= e.entries[0].dataPoint.label;
          content += "<br/>";
    
          var entries = e.entries;
          for(var j = 0; j < entries.length; j++) {
            content	+= "<span style=\"color:" + entries[j].dataSeries.color+"\"\>" + entries[j].dataSeries.name + " </span>: " + "<strong>" + entries[j].dataPoint.y + "</strong>";
            content += "<br/>"; 
          } 
          return content;
    
        }
    },

    Kindly take a look at this JSFiddle for a working example with complete code.

    Sorting values inside toolTip

    ___________
    Indranil Singh Deo
    Team CanvasJS

    #36696

    This is perfect and exactly what I was looking for. Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.