Gathering detailed insights and metrics for chartjs-plugin-colorschemes-v3
Gathering detailed insights and metrics for chartjs-plugin-colorschemes-v3
Gathering detailed insights and metrics for chartjs-plugin-colorschemes-v3
Gathering detailed insights and metrics for chartjs-plugin-colorschemes-v3
Predefined color schemes for Chart.js
npm install chartjs-plugin-colorschemes-v3
Typescript
Module System
Node Version
NPM Version
76.3
Supply Chain
98.7
Quality
75.6
Maintenance
100
Vulnerability
100
License
JavaScript (98.28%)
Shell (1.72%)
Built with Next.js • Fully responsive • SEO optimized • Open source ready
Total Downloads
68,366
Last Day
27
Last Week
1,538
Last Month
4,072
Last Year
42,113
MIT License
39 Commits
1 Forks
1 Branches
1 Contributors
Updated on Sep 13, 2022
Latest Version
0.5.4
Package Id
chartjs-plugin-colorschemes-v3@0.5.4
Unpacked Size
161.93 kB
Size
47.18 kB
File Count
11
NPM Version
8.11.0
Node Version
16.16.0
Cumulative downloads
Total Downloads
Last Day
575%
27
Compared to previous day
Last Week
137%
1,538
Compared to previous week
Last Month
-4.9%
4,072
Compared to previous month
Last Year
77.4%
42,113
Compared to previous year
1
26
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:
1npm install chartjs-plugin-colorschemes --save
To install via bower:
1bower install chartjs-plugin-colorschemes --save
To use CDN:
1<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-colorschemes"></script>
1<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.
1 options: { 2 plugins: { 3 colorschemes: { 4 scheme: 'brewer.Paired12' 5 } 6 } 7 }
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.
1import 'chartjs-plugin-colorschemes';
If you want to reduce the size by only importing the plugin core and particular color schemes, see the example below.
1// import the plugin core 2import 'chartjs-plugin-colorschemes/src/plugins/plugin.colorschemes'; 3 4// import a particular color scheme 5import { Aspect6 } from 'chartjs-plugin-colorschemes/src/colorschemes/colorschemes.office'; 6 7// ... 8 options: { 9 plugins: { 10 colorschemes: { 11 scheme: Aspect6 12 } 13 } 14 } 15//...
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.
1var customColorFunction = function(schemeColors) { 2 var myColors = ['#ff0000', '#00ff00', '#0000ff']; // define/generate own colors 3 4 // extend the color scheme with own colors 5 Array.prototype.push.apply(schemeColors, myColors); 6 7 return schemeColors; // optional: this is not needed if the array is modified in place 8}; 9 10// ... 11 options: { 12 plugins: { 13 colorschemes: { 14 scheme: 'brewer.Paired12', 15 custom: customColorFunction 16 } 17 } 18 } 19//... 20
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.
1var myColors = ['red', 'green', 'blue', 'orange', 'black', 'yellow']; 2 3// ... 4 options: { 5 plugins: { 6 colorschemes: { 7 scheme: myColors 8 } 9 } 10 } 11//... 12
You first need to install node dependencies (requires Node.js):
1npm install
The following commands will then be available from the repository root:
1gulp build # build dist files 2gulp build --watch # build and watch for changes 3gulp test # run all tests 4gulp test --watch # run all tests and watch for changes 5gulp test --coverage # run all tests and generate code coverage 6gulp lint # perform code linting 7gulp package # create an archive with dist files and samples
chartjs-plugin-colorschemes is available under the MIT license.
No vulnerabilities found.