我使用Chart.JS创建了一个图表,并希望将工具提示显示限制为1个单点。我有一个工作演示,其中当前显示的所有工具提示都可以在此处查看: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);
是否可以只为选定的数据点显示工具提示?例如,我想只有星期三,数组中的数据是390。
所需功能的屏幕截图:http://i.imgur.com/VdH4atw.png
非常感谢建议,谢谢!
答案 0 :(得分:2)
这是解决方案https://jsfiddle.net/p2yd6hut/2/ 在onAnimationComplete函数上,我创建了一个值为&gt; =到390
的新临时数组onAnimationComplete: function()
{ var tempArr = [];
this.datasets[0].points.forEach(function(point){
if(point.value >= 390){
tempArr.push(point);
}
});
this.showTooltip(tempArr, true);
}