• Stars
    star
    256
  • Rank 159,219 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Predefined color schemes for Chart.js

chartjs-plugin-colorschemes

npm Bower Travis Coverage Maintainability Awesome

Predefined color schemes for Chart.js

You can pick the perfect color combination for your charts from the predefined color schemes, which are based on popular tools such as ColorBrewer, Microsoft Office and Tableau.

This plugin requires Chart.js 2.5.0 or later.

Installation

You can download the latest version of chartjs-plugin-colorschemes from the GitHub releases.

To install via npm:

npm install chartjs-plugin-colorschemes --save

To install via bower:

bower install chartjs-plugin-colorschemes --save

To use CDN:

<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-colorschemes"></script>
<script src="https://unpkg.com/chartjs-plugin-colorschemes"></script>

Usage

chartjs-plugin-colorschemes can be used with ES6 modules, plain JavaScript and module loaders.

Include Chart.js and chartjs-plugin-colorschemes.js to your page, and specify a color scheme as shown in the example below. You can pick a scheme from Color Chart.

    options: {
        plugins: {
            colorschemes: {
                scheme: 'brewer.Paired12'
            }
        }
    }

Every color scheme has a number at the end of its name, which indicates the number of that colors included in the scheme. If the number of the datasets is larger than it, the same colors will appear repeatedly. A color is not modified if it is specified by dataset options.

Usage in ES6 as Module

Nothing else than importing the module should be enough.

import 'chartjs-plugin-colorschemes';

If you want to reduce the size by only importing the plugin core and particular color schemes, see the example below.

// import the plugin core
import 'chartjs-plugin-colorschemes/src/plugins/plugin.colorschemes';

// import a particular color scheme
import { Aspect6 } from 'chartjs-plugin-colorschemes/src/colorschemes/colorschemes.office';

// ...
    options: {
        plugins: {
            colorschemes: {
                scheme: Aspect6
            }
        }
    }
//...

Tutorial

You can find a tutorial at nagix.github.io/chartjs-plugin-colorschemes.

Configuration

The plugin options can be changed at 2 different levels and with the following priority:

  • per chart: options.plugins.colorschemes.*
  • globally: Chart.defaults.global.plugins.colorschemes.*

All available options are listed below.

Name Type Default Description
fillAlpha number 0.5 The transparency value for the line fill color. Must be a number between 0.0 (fully transparent) and 1.0 (no transparency).
scheme string|string[] 'brewer.Paired12' Color scheme name that is any of Color Chart. It also accepts an array of color strings, which is primarily for ES modules. more...
reverse boolean false If set to true, the order of the colors in the selected scheme is reversed.
override boolean false If set to true, the specified color scheme will override the existing color options. If false, it is only applied when no color setting exists. more...
custom function undefined A function that takes a copy of the color string array for scheme in order to extend the predefined scheme colors. more...

Overriding Existing Color Settings

By default, this plugin doesn't apply a color scheme if any color options are already specified. This may cause a problem if you are using a third party library such as ng-charts, which automatically applies default color settings. In that case, the existing color settings can be overridden by setting the override option to true.

custom-Function

With the help of the custom-Function you can extend the predefined scheme colors. This function takes a copy of the current scheme and is expected to return an array with at least one element. See the example below.

var customColorFunction = function(schemeColors) {
    var myColors = ['#ff0000', '#00ff00', '#0000ff']; // define/generate own colors

    // extend the color scheme with own colors
    Array.prototype.push.apply(schemeColors, myColors);

    return schemeColors; // optional: this is not needed if the array is modified in place
};

// ...
    options: {
        plugins: {
            colorschemes: {
                scheme: 'brewer.Paired12',
                custom: customColorFunction
            }
        }
    }
//...

custom colorscheme from scratch

It is possible to build your custom colorscheme from scratch (without using the custom function) by simply defining the colors it contains. See example below.

var myColors = ['red', 'green', 'blue', 'orange', 'black', 'yellow'];

// ...
    options: {
        plugins: {
            colorschemes: {
                scheme: myColors
            }
        }
    }
//...

Building

You first need to install node dependencies (requires Node.js):

npm install

The following commands will then be available from the repository root:

gulp build            # build dist files
gulp build --watch    # build and watch for changes
gulp test             # run all tests
gulp test --watch     # run all tests and watch for changes
gulp test --coverage  # run all tests and generate code coverage
gulp lint             # perform code linting
gulp package          # create an archive with dist files and samples

License

chartjs-plugin-colorschemes is available under the MIT license.

More Repositories

1

mini-tokyo-3d

A real-time 3D digital map of Tokyo's public transport system
JavaScript
2,068
star
2

chartjs-plugin-streaming

Chart.js plugin for live streaming data
JavaScript
428
star
3

nk-missile-tests

An interactive visualization of flight tests of all missiles launched by North Korea from 1984 to 2023
JavaScript
120
star
4

chartjs-plugin-rough

Chart.js plugin to create charts with a hand-drawn, sketchy, appearance
JavaScript
79
star
5

chartjs-plugin-style

Chart.js plugin for more styling options
JavaScript
61
star
6

mini-tokyo

A real-time digital map of Tokyo's public transport system
JavaScript
37
star
7

japan-eq-locator

A 3D hypocenter map of earthquakes around Japan
JavaScript
34
star
8

ukraine-livecams

Ukraine live camera 3D map
HTML
33
star
9

mapbox-gl-rain-layer

An animated rain layer for Mapbox GL JS
JavaScript
33
star
10

hakone-ekiden

A real-time 3D digital map of Hakone Ekiden
JavaScript
18
star
11

mapbox-gl-animated-popup

An animated popup component for Mapbox GL JS
JavaScript
17
star
12

chartjs-plugin-datasource

Chart.js plugin for automatic data loading
JavaScript
16
star
13

japan-weather-3d

A real-time 3D weather map of Japan
JavaScript
16
star
14

mapbox-gl-indoor-map

Indoor map based on Mapbox Indoor v1 tileset which contains 439 facilities in Japan including major stations and underground malls
JavaScript
12
star
15

sea-level-rise-3d-map

A 3D map of sea level rise simulation
HTML
8
star
16

world-eq-locator

A 3D hypocenter map of earthquakes all around the world
JavaScript
5
star
17

covid19-japan-graph

A graph of the COVID-19 clusters in Japan
JavaScript
5
star
18

japan-vaccination-tracker

A new coronavirus (COVID-19) vaccination real-time tracker with live map in Japan
JavaScript
5
star
19

nagix.github.io

JavaScript
3
star
20

mini-tokyo-3d-preview

HTML
2
star
21

mt3d-plugin-fireworks

Fireworks plugin for Mini Tokyo 3D
JavaScript
2
star
22

mt3d-plugin-livecam

Live Camera plugin for Mini Tokyo 3D
JavaScript
2
star
23

mini-sg-3d

1
star
24

covid19-aichi-graph

A graph of the COVID-19 clusters in Aichi
JavaScript
1
star
25

pien

Public transport Irregular Event Notifier (PIENπŸ₯Ί)
1
star
26

covid19-hokkaido-graph

A graph of the COVID-19 clusters in Hokkaido
JavaScript
1
star
27

mt3d-plugin-olympics2020

Tokyo 2020 Olympics plugin for Mini Tokyo 3D
JavaScript
1
star
28

mini-tokyo-3d-toei

A real-time 3D digital map of Tokyo's public transport system
JavaScript
1
star
29

covid19-tokyo-graph

A graph of the COVID-19 clusters in Tokyo
JavaScript
1
star
30

streamo

A simple chart widget for live streaming data
1
star