-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pie Graph legend on left or right is not vertically centered. #3175
Comments
@RZeni can you post screenshots of before and after your fix? I'd be happy to merge a PR fixing this |
If not resolved yet, here is what he did:
And the results: Before: Thanks btw, I was looking for it. I added the following because it seems to bug the legend when it is not on the side of the chart.
|
I took a look at this and noticed that the proposed solution would exhibit the following issues
Proposed SolutionI think the better solution to this problem would be to update Then, we provide a new config option legendOptions = {
// options are 'start', 'end', 'center'. Default is 'start' which matches old behaviour
align: 'start'
} During drawing, if the option is CC @chartjs/maintainers for input |
I think that allowing legend location configuration options as specified by @etimberg would be the best route. |
@etimberg sounds good, I prefer |
@simonbrunel that works for me |
Interesting ideas @simonbrunel I like the box align settings. I like the idea of reverse, but I'm not sure about the name. To me In terms of the pack setting, I'm not sure how feasible that is for horizontal legends. Right now, each row is filled first before going to the next. That doesn't really play well with aligning columns |
Initially, I pick
|
Hmm, I think we'll have to see how I like the name |
+1 |
I'm looking for this exact behavior. Is the above hack still the only way to fix it? |
Was this ever implemented? |
+1 |
What is the resolution on this issue? 4577 and 3175 (this) were both marked as duplicates and closed. |
@adammatthewsmith this issue has not been fixed |
@adammatthewsmith : @etimberg meant that this issue is still open (not closed). Unfortunatelly there is nobody on it right now. |
@simonbrunel the legend.align property has not been implemented yet right? are there any plans to when and if they will be implemented? is there any other oportunity to algin center a left/right legend? |
Any news on this? Currently I'm turning off the built-in legend and using the legendCallback to build my own for this reason -- which works well, but there are certain contexts where I want to use the built-in version |
is there any working model, like in JSfiddle or code pen var textWidth = ctx.measureText(legendItem.text).width, like when i checked the chart.js docs for legend i found that default boxWidth is 40 and fontSize is 12 but from where are you getting the legendItem , x , y and what is me for the below code ? also legendItems if(me.options.position == 'left' || me.options.position == 'right') |
Any update on this guys? :) |
If someone could explain chich part of the draw function to edit it would be nice |
line 11790 var itemHeight = fontSize + labelOpts.padding; |
Hello, I had the same problem. I changed the contents of line 11792 per y: me.top + labelOpts.padding + (me.height - ((fontSize + labelOpts.padding) * me.legendItems.length)) / 2, |
I want to align legend items to the right centre. Any update on this? |
I need to align it left, any update??????? |
… for controlling alignment of legend blocks in horizontal/vertical legends. Maintains backward compatibility for legends positioned on the left/right by defaulting to 'start'.
…mage based unit tests
- New config parameter options.legened.align, for controlling alignment of legend blocks in horizontal/vertical legends. - Maintains backward compatibility for legends positioned on the left/right by defaulting to 'start'. - Replacing nearby pixel unit tests for legend with image based tests - Documentation for options.legend.align
- New config parameter options.legened.align, for controlling alignment of legend blocks in horizontal/vertical legends. - Maintains backward compatibility for legends positioned on the left/right by defaulting to 'start'. - Replacing nearby pixel unit tests for legend with image based tests - Documentation for options.legend.align
- New config parameter options.legend.align, for controlling alignment of legend blocks in horizontal/vertical legends. - Maintains backward compatibility for legends positioned on the left/right by defaulting to 'start'. - Replacing nearby pixel unit tests for legend with image based tests - Documentation for options.legend.align
I have fixed this in my local copy by adding the following line into the draw function
y += (ctx.canvas.clientHeight - (itemHeight * me.legendItems.length)) / 2;
The text was updated successfully, but these errors were encountered: