-
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
Issue 1764: Add default colors for Pie Charts #1834
Issue 1764: Add default colors for Pie Charts #1834
Conversation
@@ -92,6 +92,10 @@ | |||
}, | |||
addData : function(segment, atIndex, silent){ | |||
var index = atIndex !== undefined ? atIndex : this.segments.length; | |||
if ( typeof(segment.color) === "undefined" ) { | |||
segment.color = Chart.defaults.global.segmentColorDefault[index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be safer to use index % Chart.defaults.global.segmentColorDefault.length
It is unlikely that there would be more than 15 segments, but someone could change the array to a shorter one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely a good call. I added a commit to revise this.
Overall looks pretty good. Did you see https://github.com/nnnick/Chart.js/blob/master/src/Chart.Doughnut.js#L76 as well? |
@etimberg I hadn't seen that. I'm not sure I get exactly what that's doing without context and I'm not sure if it needs to be patched to support this change. Forgive me, JS isn't my primary language. I'm happy to finish out the change but I need a little guidance if you would. Thanks |
I'm going to take a look at the default color set too. I kind of just picked a random set but I'm sure I could choose a better set of colors/highlights that make them go better together. |
I don't think it needs to be patched to support it. It simply adds a random colour if one is not added. Let me know when you've settled on the final colour set and I'll merge this. Thanks for the PR 😄 |
@etimberg I chose to use 12 colors instead of the 15(?) I had before. I read somewhere that that's the most an eye can process. I also tried to pick good main/highlight colors. It looks good to me. You can merge when you feel it passes muster. You're welcome for the PR. Thanks for the excellent project! It is the tool that I needed to make my work beautiful. |
Tested, looks nice! Great colour choices! |
…fault-pie-chart-colors Issue 1764: Add default colors for Pie Charts
I wrote a simple fix for default colors on the pie chart.
Here's the basic idea:
Users can then override the list of default colors/highlights at a global level should they feel the predefined ones are not adequate/enough. Failure to define colors will simply roll over to the defaults.