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

Legend styling issue (not custom legend)

Open Dergonic opened this issue 10 years ago • 3 comments

I'm using the common legend for a stacked barchart on a responsive chart.

Here is the related config :

legend:{
    display: true,
    position: 'bottom',
    fullWidth:true,
    labels:{
        boxWidth:30 //Width legend colorbox
    }
}

It looks good for about all resolution EXCEPT when canvas width is between 520 and 560px.

I have 4 legends. When i reduce the size, The 4th goes in the line very well image

But when it is time for the 3rd to go on the line also (at about canvas's width=560px), it does not go on the left of 4th, but take its place and the 4th goes... somewhere (It is not more visible) image

It seems the whole legend is a bit on the left. the 1st colorbloc is trimmed on his left (see capture) and there is some blank space on the right of the legend.

What is really strange is that if I go on reducing the size of the window (at about canvas's width=520px), the Yaxes is adapting (showing less ticks). At this time, the legend is back displaying good ! (3 on 1st line and 1 on the second line ... like before the bug) And when I reach a canvas that is 506px wide, the legend goes well on 2 lines of two element each image

After having look for a solution, I've some idea, but did not find the right situation For example, on src/core/core.legend.js line 189. there is no mention of the box border (which is 3px wide for me). Is it a possible cause ? I don't know at all

Another example, on line 192, you create a "new line" which is 'this.left' width. But in line 181, the first you create is '0' width. Might it be 'this.left' too ?

Dergonic avatar Feb 01 '16 10:02 Dergonic

Great points (get it :smile:). If the border is not mentioned, then we need to get that accounted for, for sure. As for the line, I'm not sure the reasoning behind the 0 and the line.left. I won't be able to take a look for a while, but if you want to give it a try for a fix, and just report back your findings, that might be faster than my personal timeline right now.

tannerlinsley avatar Feb 01 '16 16:02 tannerlinsley

For information, after the updates of these last days, I do not succeed on having the same bug! It looks like one of them solved the situation

So I think this issue could now be closed

Dergonic avatar Feb 03 '16 09:02 Dergonic

@Dergonic great that it got fixed. Not sure what did it.

etimberg avatar Feb 03 '16 12:02 etimberg