Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export default class TimeScale extends Scale {
if (timeOpts.tooltipFormat) {
return adapter.format(value, timeOpts.tooltipFormat);
}
return adapter.format(value, timeOpts.displayFormats.datetime);
return adapter.format(value, timeOpts.displayFormats[this._unit] || timeOpts.displayFormats.datetime);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions test/specs/scale.time.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,42 @@ describe('Time scale tests', function() {
}
});

it('getLabelForValue should use the current unit displayFormat, not datetime (issue #12128)', function() {
var chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
xAxisID: 'x',
data: [
{x: '2015-01-01', y: 10},
{x: '2015-02-01', y: 20},
{x: '2015-03-01', y: 30}
]
}]
},
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'month',
displayFormats: {
month: 'MMM YYYY'
}
}
}
}
}
});

var xScale = chart.scales.x;
var controller = chart.getDatasetMeta(0).controller;
var value = controller.getParsed(0)[xScale.id];

// Should use 'month' displayFormat ('MMM YYYY'), not 'datetime'
expect(xScale.getLabelForValue(value)).toBe('Jan 2015');
});

it('should round to isoWeekday', function() {
var chart = window.acquireChart({
type: 'line',
Expand Down