0.5.0 • Published 5 years ago

chartjs-plugin-style v0.5.0

Weekly downloads
8,027
License
MIT
Repository
github
Last release
5 years ago

chartjs-plugin-style

npm Bower Travis Code Climate Awesome

Chart.js plugin for more styling options

This plugin requires Chart.js 2.6.0 or later.

Installation

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

To install via npm:

npm install chartjs-plugin-style --save

To install via bower:

bower install chartjs-plugin-style --save

To use CDN:

<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-style@latest/dist/chartjs-plugin-style.min.js"></script>
<script src="https://unpkg.com/chartjs-plugin-style@latest/dist/chartjs-plugin-style.min.js"></script>

Usage

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

chartjs-plugin-style requires Chart.js. Include Chart.js and chartjs-plugin-style.js to your page to enable style options.

Version 0.5 supports the bevel, drop shadow, inner glow, outer glow and overlay effects for datasets and the tooltip. More options are to be added in the upcoming releases.

Usage in ES6 as module

Nothing else than importing the module should be enough.

import 'chartjs-plugin-style';

Tutorial and Samples

You can find a tutorial and samples at nagix.github.io/chartjs-plugin-style.

Configuration

To configure this plugin, you can simply add the following properties to your datasets and tooltip. point* properties are used only in line, radar and scatter charts. hover* properties are not used in a tooptip.

NameTypeScriptableIndexableDefault
backgroundOverlayColorColorYesYes'rgba(0, 0, 0, 0)'
backgroundOverlayModestringYesYes'source-over'
bevelWidthnumberYesYes0
bevelHighlightColorColorYesYes'rgba(0, 0, 0, 0)'
bevelShadowColorColorYesYes'rgba(0, 0, 0, 0)'
hoverBackgroundOverlayColorColorYesYes'rgba(0, 0, 0, 0)'
hoverBackgroundOverlayModestringYesYes'source-over'
hoverBevelWidthnumberYesYes0
hoverBevelHighlightColorColorYesYes'rgba(0, 0, 0, 0)'
hoverBevelShadowColorColorYesYes'rgba(0, 0, 0, 0)'
hoverInnerGlowWidthnumberYesYes0
hoverInnerGlowColorColorYesYes'rgba(0, 0, 0, 0)'
hoverOuterGlowWidthnumberYesYes0
hoverOuterGlowColorColorYesYes'rgba(0, 0, 0, 0)'
hoverShadowOffsetXnumberYesYes0
hoverShadowOffsetYnumberYesYes0
hoverShadowBlurnumberYesYes0
hoverShadowColorColorYesYes'rgba(0, 0, 0, 0)'
innerGlowWidthnumberYesYes0
innerGlowColorColorYesYes'rgba(0, 0, 0, 0)'
outerGlowWidthnumberYesYes0
outerGlowColorColorYesYes'rgba(0, 0, 0, 0)'
pointBackgroundOverlayColorColorYesYes'rgba(0, 0, 0, 0)'
pointBackgroundOverlayModestringYesYes'source-over'
pointBevelWidthnumberYesYes0
pointBevelHighlightColorColorYesYes'rgba(0, 0, 0, 0)'
pointBevelShadowColorColorYesYes'rgba(0, 0, 0, 0)'
pointHoverBackgroundOverlayColorColorYesYes'rgba(0, 0, 0, 0)'
pointHoverBackgroundOverlayModestringYesYes'source-over'
pointHoverBevelWidthnumberYesYes0
pointHoverBevelHighlightColorColorYesYes'rgba(0, 0, 0, 0)'
pointHoverBevelShadowColorColorYesYes'rgba(0, 0, 0, 0)'
pointHoverInnerGlowWidthnumberYesYes0
pointHoverInnerGlowColorColorYesYes'rgba(0, 0, 0, 0)'
pointHoverOuterGlowWidthnumberYesYes0
pointHoverOuterGlowColorColorYesYes'rgba(0, 0, 0, 0)'
pointHoverShadowOffsetXnumberYesYes0
pointHoverShadowOffsetYnumberYesYes0
pointHoverShadowBlurnumberYesYes0
pointHoverShadowColorColorYesYes'rgba(0, 0, 0, 0)'
pointInnerGlowWidthnumberYesYes0
pointInnerGlowColorColorYesYes'rgba(0, 0, 0, 0)'
pointOuterGlowWidthnumberYesYes0
pointOuterGlowColorColorYesYes'rgba(0, 0, 0, 0)'
pointShadowOffsetXnumberYesYes0
pointShadowOffsetYnumberYesYes0
pointShadowBlurnumberYesYes0
pointShadowColorColorYesYes'rgba(0, 0, 0, 0)'
shadowOffsetXnumberYesYes0
shadowOffsetYnumberYesYes0
shadowBlurnumberYesYes0
shadowColorColorYesYes'rgba(0, 0, 0, 0)'

Shadow effect

The shadow effect can be controlled with the following properties.

NameDescription
shadowOffsetXIndicates the horizontal distance the shadow should extend from the line. See MDN.
shadowOffsetYIndicates the vertical distance the shadow should extend from the line. See MDN.
shadowBlurIndicates the size of the blurring effect for the line; this value doesn't correspond to a number of pixels. See MDN.
shadowColorA standard CSS color value indicating the color of the shadow effect for the line. See Colors.
hoverShadowOffsetXThe horizontal distance the shadow should extend from the element when hovered.
hoverShadowOffsetYThe vertical distance the shadow should extend from the element when hovered.
hoverShadowBlurThe size of the blurring effect when hovered.
hoverShadowColorThe color of the shadow effect when hovered.
pointShadowOffsetXThe horizontal distance the shadow should extend from the point.
pointShadowOffsetYThe vertical distance the shadow should extend from the point.
pointShadowBlurThe size of the blurring effect for the point.
pointShadowColorThe color of the shadow effect for the point.
pointHoverShadowOffsetXThe horizontal distance the shadow should extend from the point when hovered.
pointHoverShadowOffsetYThe vertical distance the shadow should extend from the point when hovered.
pointHoverShadowBlurThe size of the blurring effect for the point when hovered.
pointHoverShadowColorThe color of the shadow effect for the point when hovered.

If the value is undefined, point* values fallback first to the dataset options then to the associated elements.point.* options. The rest of the values fallback to the associated elements.{element type}.* options.

Bevel effect

The bevel effect can be controlled with the following properties.

NameDescription
bevelWidthThe width of the bevel effect.
bevelHighlightColorThe highlight color of the bevel effect.
bevelShadowColorThe shadow color of the bevel effect.
hoverBevelWidthThe width of the bevel effect when hovered.
hoverBevelHighlightColorThe highlight color of the bevel effect when hovered.
hoverBevelShadowColorThe shadow color of the bevel effect when hovered.
pointBevelWidthThe width of the bevel effect for the point.
pointBevelHighlightColorThe highlight color of the bevel effect for the point.
pointBevelShadowColorThe shadow color of the bevel effect for the point.
pointHoverBevelWidthThe width of the bevel effect for the point when hovered.
pointHoverBevelHighlightColorThe highlight color of the bevel effect for the point when hovered.
pointHoverBevelShadowColorThe shadow color of the bevel effect for the point when hovered.

If the value is undefined, point* values fallback first to the dataset options then to the associated elements.point.* options. The rest of the values fallback to the associated elements.{element type}.* options.

Glow effects

The glow effect can be controlled with the following properties.

NameDescription
innerGlowWidthThe width of the inner glow effect.
innerGlowColorThe color of the inner glow effect.
outerGlowWidthThe width of the outer glow effect.
outerGlowColorThe color of the outer glow effect.
hoverInnerGlowWidthThe width of the inner glow effect when hovered.
hoverInnerGlowColorThe color of the inner glow effect when hovered.
hoverOuterGlowWidthThe width of the outer glow effect when hovered.
hoverOuterGlowColorThe color of the outer glow effect when hovered.
pointInnerGlowWidthThe width of the inner glow effect for the point.
pointInnerGlowColorThe color of the inner glow effect for the point.
pointOuterGlowWidthThe width of the outer glow effect for the point.
pointOuterGlowColorThe color of the outer glow effect for the point.
pointHoverInnerGlowWidthThe width of the inner glow effect for the point when hovered.
pointHoverInnerGlowColorThe color of the inner glow effect for the point when hovered.
pointHoverOuterGlowWidthThe width of the outer glow effect for the point when hovered.
pointHoverOuterGlowColorThe color of the outer glow effect for the point when hovered.

If the value is undefined, point* values fallback first to the dataset options then to the associated elements.point.* options. The rest of the values fallback to the associated elements.{element type}.* options.

Overlay effect

The overlay effect can be controlled with the following properties. Note that these properties are not used in a tooltip.

NameDescription
backgroundOverlayColorThe background color overlaid on the element, which can be a standard CSS color value, a CanvasPattern or CanvasGradient object. See Colors.
backgroundOverlayModeIndicates the type of compositing operation to apply when overlaying a color. See MDN.

| hoverBackgroundOverlayColor | hoverBackgroundOverlayMode | Indicates the type of compositing operation to apply when overlaying a color when hovered. | pointBackgroundOverlayColor | The background color overlaid on the point. | pointBackgroundOverlayMode | Indicates the type of compositing operation to apply when overlaying a color on the point. | pointHoverBackgroundOverlayColor | The background color overlaid on the point when hovered. | pointHoverBackgroundOverlayMode | Indicates the type of compositing operation to apply when overlaying a color on the point when hovered.

If the value is undefined, point* values fallback first to the dataset options then to the associated elements.point.* options. The rest of the values fallback to the associated elements.{element type}.* options.

Example usage

{
    type: 'line',
    data: {
        labels: ['January', 'February', 'March', 'April', 'May', 'June'],
        datasets: [{
            data: [45, 20, 64, 32, 76, 51],
            shadowOffsetX: 3,
            shadowOffsetY: 3,
            shadowBlur: 10,
            shadowColor: 'rgba(0, 0, 0, 0.5)',
            pointBevelWidth: 3,
            pointBevelHighlightColor: 'rgba(255, 255, 255, 0.75)',
            pointBevelShadowColor: 'rgba(0, 0, 0, 0.5)',
            pointShadowOffsetX: 3,
            pointShadowOffsetY: 3,
            pointShadowBlur: 10,
            pointShadowColor: 'rgba(0, 0, 0, 0.5)',
            pointHoverInnerGlowWidth: 20,
            pointHoverInnerGlowColor: 'rgba(255, 255, 0, 0.5)',
            pointHoverOuterGlowWidth: 20,
            pointHoverOuterGlowColor: 'rgba(255, 255, 0, 1)',
            backgroundOverlayColor: ctx.createPattern(img, 'repeat'),
            backgroundOverlayMode: 'multiply'
        }]
    },
    options: {
        tooltips: {
            bevelWidth: 3,
            bevelHighlightColor: 'rgba(255, 255, 255, 0.75)',
            bevelShadowColor: 'rgba(0, 0, 0, 0.5)'
            shadowOffsetX: 3,
            shadowOffsetY: 3,
            shadowBlur: 10,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
    }
}

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 lint             # perform code linting
gulp package          # create an archive with dist files and samples

License

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