Skip to content

Commit 4130c31

Browse files
MPierre9dracos
authored andcommitted
Fix label vertical alignment on vertical scales (chartjs#5248)
1 parent a540b0e commit 4130c31

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/core/core.scale.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,15 @@ module.exports = function(Chart) {
875875

876876
var label = itemToDraw.label;
877877
if (helpers.isArray(label)) {
878-
for (var i = 0, y = 0; i < label.length; ++i) {
878+
var lineCount = label.length;
879+
var lineHeight = tickFont.size * 1.5;
880+
var y = me.isHorizontal() ? 0 : -lineHeight * (lineCount - 1) / 2;
881+
882+
for (var i = 0; i < lineCount; ++i) {
879883
// We just make sure the multiline element is a string here..
880884
context.fillText('' + label[i], 0, y);
881885
// apply same lineSpacing as calculated @ L#320
882-
y += (tickFont.size * 1.5);
886+
y += lineHeight;
883887
}
884888
} else {
885889
context.fillText(label, 0, 0);

0 commit comments

Comments
 (0)