You need to kind of take control over the tootip generation process (i.e. copy paste the relevant section of code from the Chart.js library :-))
Show Tooltips automatically (without hover) for Multi Series Line Charts
Here's how its going to look
Just change your options like this
var options = {
showTooltips: true,
onAnimationComplete: function () {
for (var dataIndex = 0; dataIndex < this.datasets[0].points.length; dataIndex++) {
// the following is pretty much a copy-paste from the Chart.js library
var tooltipLabels = [],
tooltipColors = [],
medianPosition = (function (index) {
// Get all the points at that particular index
var Elements = [],
dataCollection,
xPositions = [],
yPositions = [],
xMax,
yMax,
xMin,
yMin;
Chart.helpers.each(this.datasets, function (dataset) {
dataCollection = dataset.points;
if (dataCollection[dataIndex] && dataCollection[dataIndex].hasValue()) {
Elements.push(dataCollection[dataIndex]);
}
});
Chart.helpers.each(Elements, function (element) {
xPositions.push(element.x);
yPositions.push(element.y);
//Include any colour information about the element
tooltipLabels.push(Chart.helpers.template(this.options.multiTooltipTemplate, element));
tooltipColors.push({
fill: element._saved.fillColor || element.fillColor,
stroke: element._saved.strokeColor || element.strokeColor
});
}, this);
yMin = Chart.helpers.min(yPositions);
yMax = Chart.helpers.max(yPositions);
xMin = Chart.helpers.min(xPositions);
xMax = Chart.helpers.max(xPositions);
return {
x: (xMin > this.chart.width / 2) ? xMin : xMax,
y: (yMin + yMax) / 2
};
}).call(this, dataIndex);
new Chart.MultiTooltip({
x: medianPosition.x,
y: medianPosition.y,
xPadding: this.options.tooltipXPadding,
yPadding: this.options.tooltipYPadding,
xOffset: this.options.tooltipXOffset,
fillColor: this.options.tooltipFillColor,
textColor: this.options.tooltipFontColor,
fontFamily: this.options.tooltipFontFamily,
fontStyle: this.options.tooltipFontStyle,
fontSize: this.options.tooltipFontSize,
titleTextColor: this.options.tooltipTitleFontColor,
titleFontFamily: this.options.tooltipTitleFontFamily,
titleFontStyle: this.options.tooltipTitleFontStyle,
titleFontSize: this.options.tooltipTitleFontSize,
cornerRadius: this.options.tooltipCornerRadius,
labels: tooltipLabels,
legendColors: tooltipColors,
legendColorBackground: this.options.multiTooltipKeyBackground,
title: this.scale.xLabels[dataIndex],
chart: this.chart,
ctx: this.chart.ctx,
custom: this.options.customTooltips
}).draw();
}
},
tooltipEvents: [],
datasetFill: true,
}
Fiddle - https://jsfiddle.net/racqd639/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…