You must be logged in to post your query.
Home › Forums › Chart Support › No Way to Sort Tooltip?
Tagged: sorting, tooltip
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?
@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.
___________ Indranil Singh Deo Team CanvasJS
This is perfect and exactly what I was looking for. Thanks!
You must be logged in to reply to this topic. Login/Register