mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Let tooltips use time formatted labels if they exist
This commit is contained in:
parent
c2a7e4c251
commit
88d30d8c93
@ -164,7 +164,11 @@
|
||||
x: medianPosition.x,
|
||||
y: medianPosition.y,
|
||||
labels: labels,
|
||||
title: this._data.labels && this._data.labels.length ? this._data.labels[this._active[0]._index] : '',
|
||||
title: (function() {
|
||||
return this._data.timeLabels ? this._data.timeLabels[this._active[0]._index] :
|
||||
(this._data.labels && this._data.labels.length) ? this._data.labels[this._active[0]._index] :
|
||||
'';
|
||||
}).call(this),
|
||||
legendColors: colors,
|
||||
legendBackgroundColor: this._options.tooltips.multiKeyBackground,
|
||||
});
|
||||
|
||||
@ -69,6 +69,8 @@
|
||||
this.labels = [];
|
||||
// A map of original labelIndex to time labelIndex
|
||||
this.timeLabelIndexMap = {};
|
||||
// The time formatted versions of the labels for use by tooltips
|
||||
this.data.timeLabels = [];
|
||||
|
||||
var definedMoments = [];
|
||||
|
||||
@ -134,6 +136,10 @@
|
||||
|
||||
helpers.each(definedMoments, function(definedMoment, index) {
|
||||
this.timeLabelIndexMap[index] = momentRangeLength - this.lastMoment.diff(definedMoment, this.timeUnit);
|
||||
this.data.timeLabels.push(
|
||||
definedMoment
|
||||
.format(this.options.time.display ? this.options.time.display : this.displayFormat)
|
||||
);
|
||||
}, this);
|
||||
|
||||
// For every unit in between the first and last moment, create a moment and add it to the labels tick
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user