Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Change Label orientation on x-Axis for Bar Charts

Open Kaj80 opened this issue 3 years ago • 6 comments

Expected behavior

Hi,

I rotated the X axis labels 90 degrees. The labels are not in line with the chart as you can see they are slightly shifted to the right. I removed the css style, but it didn't change anything, it looks like a problem with the script.

Screenshot

chart.js version

v3.9.1

Kaj80 avatar Nov 02 '22 16:11 Kaj80

Please when you submit a bug report add a reproducable sample, the field is mandatory for a reason so it saves us time trying to reproduce it and asking for a reproducable sample if we can't reproduce it

LeeLenaleee avatar Nov 02 '22 17:11 LeeLenaleee

Hi,

My code:

new Chart(conversionsChart, { type: 'bar', options: { scales: { y: { ticks: { callback: function (val) { return val + '%'; }, }, }, x: { ticks: { autoSkip: false, maxRotation: 90, minRotation: 90 } }, }, }, data: { labels: [ 'Oct 1', 'Oct 2', 'Oct 3', 'Oct 4', 'Oct 5', 'Oct 6', 'Oct 7', 'Oct 8', 'Oct 9', 'Oct 10', 'Oct 11', 'Oct 12', ], datasets: [ { label: '2020', data: [25, 20, 30, 22, 17, 10, 18, 26, 28, 26, 20, 32], }, { label: '2019', data: [15, 10, 20, 12, 7, 0, 8, 16, 18, 16, 10, 22], backgroundColor: '#d2ddec', hidden: true, }, ], }, });

Kaj80 avatar Nov 02 '22 17:11 Kaj80

Hi,

All settings and styles are removed and the labels are still shifted.

Screenshot

Kaj80 avatar Nov 02 '22 19:11 Kaj80

Reproducible: https://codepen.io/cmcnulty/pen/LYrNoPQ that said, whether it's centered on the top, middle or bottom of the text seems somewhat subjective to me.

cmcnulty avatar Nov 03 '22 14:11 cmcnulty

2 cents. It seems to be solved in version 4. Trying in your codepen with https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js, the ticks sounds to be drawn correctly.

stockiNail avatar Nov 03 '22 15:11 stockiNail

2 cents. It seems to be solved in version 4. Trying in your codepen with https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js, the ticks sounds to be drawn correctly.

Thank you for the info :)

Kaj80 avatar Nov 05 '22 10:11 Kaj80

Fixed in V4 https://codepen.io/leelenaleee/pen/rNqWBQz

LeeLenaleee avatar Apr 19 '23 23:04 LeeLenaleee