
Security News
libxml2 Maintainer Ends Embargoed Vulnerability Reports, Citing Unsustainable Burden
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
chartjs-plugin-colorschemes-v3
Advanced tools
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.
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>
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.
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
}
}
}
//...
You can find a tutorial at nagix.github.io/chartjs-plugin-colorschemes.
The plugin options can be changed at 2 different levels and with the following priority:
options.plugins.colorschemes.*
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. |
overrideExisting | 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... |
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 overrideExisting
option to true
.
custom
-FunctionWith 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 scratchIt 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
}
}
}
//...
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
chartjs-plugin-colorschemes is available under the MIT license.
FAQs
Predefined color schemes for Chart.js
The npm package chartjs-plugin-colorschemes-v3 receives a total of 681 weekly downloads. As such, chartjs-plugin-colorschemes-v3 popularity was classified as not popular.
We found that chartjs-plugin-colorschemes-v3 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.