Chart.js: Chart does not use automatic colors for lines

Created on 24 Aug 2018  路  7Comments  路  Source: chartjs/Chart.js

When creating a line chart with 2 or more series, no automatic color for each line is created. It seems default color (gray) is used for all of them.

By assigning a color explicitly is not an option since the series information comes from database, so I cannot know how many series exist before hand.

This should be solved to make this chart more useful.

Regards
Jaime

enhancement

Most helpful comment

Why don't you use an array with colors, and just grap those colors depending on # of dataset?
All my charts are dynamic and I use Chroma.js to get my colors, depending on what type of chart I use

return chroma.scale([color1, color2]).mode('lch').colors(numberOfColors);

return chroma.scale(['#33b5cc', '#cf1766']).mode('lch').colors(13);

or if you want to be more specific in the color change:

return chroma.scale(['#33b5cc', '#ff9100', '#cf1766']).mode('lch').colors(13);

All 7 comments

Why don't you use an array with colors, and just grap those colors depending on # of dataset?
All my charts are dynamic and I use Chroma.js to get my colors, depending on what type of chart I use

return chroma.scale([color1, color2]).mode('lch').colors(numberOfColors);

return chroma.scale(['#33b5cc', '#cf1766']).mode('lch').colors(13);

or if you want to be more specific in the color change:

return chroma.scale(['#33b5cc', '#ff9100', '#cf1766']).mode('lch').colors(13);

I think plugin should be easier to use... that handling is very complicated for such a recurring task. But never mind.. I stopped using ChartJS and starting using other that defines color automatically for each serie among other powerful features.

This should be enhanced in ChartJS as soon as possible.

Regards
Jaime

I just released chartjs-plugin-colorschemes that enables automatic coloring. GitHub repository is here.

+1 here. Google Charts has such capability and and it would be great to have a simple migration path away from it. At this moment, I'm going to look on other libraries.

@php-coder what's the issue using chartjs-plugin-colorschemes?

@simonbrunel I haven't tried it because I'd like to have something simple that works out-of-box. Also I don't want to have one more dependency (that also doesn't exist on webjars.org).

Closing because I don't believe this will be a feature of the core library. The colorschemes plugin is the best way to achieve this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gouthamrv picture gouthamrv  路  3Comments

gabrieldesouza picture gabrieldesouza  路  3Comments

adriantombu picture adriantombu  路  3Comments

akashrajkn picture akashrajkn  路  3Comments

Woogles picture Woogles  路  3Comments