Reputation: 23
I've made a chart using Chart.JS and am hoping to limit the tooltip display to 1 single point. I have a working demo where all tooltips are currently being displayed that can be viewed here: https://jsfiddle.net/p2yd6hut/
var data1 = {
labels : ["SUN","MON","TUE","WED","THU","FRI","SAT"],
datasets : [
{
fillColor : "rgba(255,255,255,.1)",
strokeColor : "rgba(0,0,0,.25)",
pointColor : "#0af",
pointStrokeColor : "rgba(255,255,255,1)",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(220,220,220,1)",
data : [150,200,235,390,290,250,250]
}
]
}
var options1 = {
scaleFontColor : "rgba(0,0,0,1)",
scaleLineColor : "rgba(0,0,0,.1)",
scaleGridLineColor : "rgba(0,0,0,.1)",
scaleShowGridLines : true,
scaleShowLabels : false,
scaleShowHorizontalLines : false,
bezierCurve : false,
scaleOverride : true,
scaleSteps : 5,
scaleStepWidth : 100,
tooltipTemplate: "<%= value %>" + "Guests",
showTooltips: true,
tooltipFillColor: "#0af",
onAnimationComplete: function() {
this.showTooltip(this.datasets[0].points, true);
},
tooltipEvents: []
}
new Chart(c1.getContext("2d")).Line(data1,options1);
Is it possible to only have a tooltip display for a selected datapoint? For instance, I'd like to only have Wednesday where the data is 390 in the array.
Screenshot of desired functionality: https://i.sstatic.net/sKYtx.png
Advice is greatly appreciated, thanks!
Upvotes: 1
Views: 2464
Reputation: 424
this is the solution https://jsfiddle.net/p2yd6hut/2/ on the function onAnimationComplete i have created a new temp array with the value >= to 390
onAnimationComplete: function()
{ var tempArr = [];
this.datasets[0].points.forEach(function(point){
if(point.value >= 390){
tempArr.push(point);
}
});
this.showTooltip(tempArr, true);
}
Upvotes: 2