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

y-axis labels are being cut off when many data values displayed

Open googol7 opened this issue 12 years ago • 29 comments

Big numbers are cut off in the y-axis:

30000 (you almost can't see the "3" anymore) 25000 (you almost can't see the "2" anymore) 20000 (you almost can't see the "2" anymore) 15000 1000

See this example:

http://jsbin.com/cigoxefoxe/1/edit?html,js,output

googol7 avatar Oct 28 '14 17:10 googol7

The values are there. If you give the canvas object style padding it will add white space around the chart. For example:

<canvas id="myChart" width=800px height="400" style="border: 2px solid black; padding:20px;" http://jsbin.com/jayutaqela/1/edit?html,js,output

chart example

Does that fix the problem? If not can you please be more spcific and take a picture of it and point to exactly what your talking about? thanks.

sweetgoals avatar Oct 29 '14 15:10 sweetgoals

I think the issue is just the font. The left edge of the '2' and the '3' at quick glance looks like it is cut off but in actual fact it's just the font.

etimberg avatar Oct 29 '14 22:10 etimberg

Padding does not help here. It seems to be the font. I'm on Mac OS X 10.9.5. It's the same in all browsers (Chrome, Safari, Firefox). See the screenshot attached:

bildschirmfoto 2014-10-29 um 23 57 34

googol7 avatar Oct 29 '14 22:10 googol7

Running windows 8 and chrome. I don't get that issue.

sweetgoals avatar Oct 30 '14 14:10 sweetgoals

It depends on the browser language! If you set your browser language to german it will cut the labels off - if it's english it won't. But I couldn't reproduce it in jsbin yet. Attached two screenshots from my app. english german

googol7 avatar Oct 31 '14 09:10 googol7

I'm wondering if you attach a font script to it if that will override the system font. On the main page for chart.js he uses a link for http://use.typekit.net/dqv7hih.js. I created a link:http://jsbin.com/tekifukaro/1/watch?html,js,output Does it help?

sweetgoals avatar Oct 31 '14 15:10 sweetgoals

Nope:

bildschirmfoto 2014-10-31 um 16 18 19

googol7 avatar Oct 31 '14 15:10 googol7

hmmm... What about trying to change the fonts for the graphs? Supports a few. // String - Scale label font declaration for the scale label scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",

// Number - Scale label font size in pixels
scaleFontSize: 12,

You could also add your own if you changed the Chart.js file. I really can't help that much with this one. I don't have a mac.

sweetgoals avatar Oct 31 '14 19:10 sweetgoals

If you look closely at the English screenshot, you see that the 3's and 2's are still cut off.

I have the same problem with my line chart.

I strongly believe the issue is related to the inaccuracy of the browser's context.measureText-method used in the longestText-helper.

Adding 5% more width "solved" the issue for me, but this isn't a pretty fix.

Update: Other possible way to "fix" the issue.

pfirpfel avatar Nov 04 '14 08:11 pfirpfel

This issue is caused because in determining the tilt of the x-axis labels, chartjs checks for yLabelWidth + 8 and everywhere else it uses yLabelWidth + 10. Language and font can affect this because they both influence the line length, which is used to determine the tilt.

My pr, which @pfirpfel linked, addresses this issue by adding 10 when chartjs sets yLabelWidth and removes the + 10/+ 8 checks everywhere. In my tests it completely fixed the issue. Unfortunately it's been open for a nearly a month, so I don't know when it will be merged.

rylanhalteman avatar Nov 04 '14 18:11 rylanhalteman

@sweetgoals: it's independent from the scaleFontSize setting 11 12 10 13 14

googol7 avatar Nov 04 '14 18:11 googol7

were you able to reproduce this on windows in chrome? I wasn't able to reproduce the problem on windows.

sweetgoals avatar Nov 06 '14 17:11 sweetgoals

Chrome @ Windows 8.1 displays it correctly without cropping.

googol7 avatar Nov 06 '14 18:11 googol7

OSX user here, still doesn't work in OSX 10.9.5

boroth avatar Dec 10 '14 22:12 boroth

I have this issue too. I am setting my Y label by using:

var options = { scaleLabel: "<%= Number(value / 1000) + ' MB'%>" };

Then, I put an extra space between " and <, making my code:

var options = { scaleLabel: " <%= Number(value / 1000) + ' MB'%>" };

This fixed the issue for me for the time being.

theverex avatar Dec 18 '14 23:12 theverex

The problem occurs when the loop that calculates this.xScalePaddingLeft in calculateXLabelRotation() reduces the value to less than the value required to draw the Y axis labels.

The solution is to revert this.xScalePaddingLeft to its previous value after the loop.

BenMic avatar Jan 01 '15 15:01 BenMic

I am seeing this issue as well :+1:

jivinivan avatar Jan 07 '15 18:01 jivinivan

Adding a space in the scaleLabel worked for me as well (temporary solution of course).

jivinivan avatar Jan 07 '15 21:01 jivinivan

It seems that @rylanhalteman found a fix. Is this annoying core issue going to be fixed in near future? Charts are broken for a lot of users.

wildchild avatar Apr 12 '15 09:04 wildchild

@wildchild I merged #677 so you should be good to go. Sorry that it took a while to get this into the core.

etimberg avatar Apr 12 '15 12:04 etimberg