Plugins

    Plugins can be shared between chart instances:

    Plugins can also be defined directly in the chart config (a.k.a. inline plugins):

    WARNING

    inline plugins are not registered. Some plugins require registering, i.e. can’t be used inline.

    1. const chart = new Chart(ctx, {
    2. plugins: [{
    3. //..
    4. }
    5. }]
    6. });

    However, this approach is not ideal when the customization needs to apply to many charts.

    Plugins can be registered globally to be applied on all charts (a.k.a. global plugins):

    WARNING

    Plugins must define a unique id in order to be configurable.

    This id should follow the npm package name convention (opens new window):

    • can’t start with a dot or an underscore
    • can’t contain any non-URL-safe characters
    • can’t contain uppercase letters
    • should be something short, but also reasonably descriptive

    If a plugin is intended to be released publicly, you may want to check the to see if there’s something by that name already. Note that in this case, the package name should be prefixed by chartjs-plugin- to appear in Chart.js plugin registry.

    Plugin options

    Plugin options are located under the options.plugins config and are scoped by the plugin ID: options.plugins.{plugin-id}.

    1. const chart = new Chart(ctx, {
    2. foo: { ... }, // chart 'foo' option
    3. plugins: {
    4. p1: {
    5. bar: { ... }
    6. },
    7. p2: {
    8. foo: { ... }, // p2 plugin 'foo' option
    9. bla: { ... }
    10. }
    11. }
    12. });

    Disable plugins

    To disable a global plugin for a specific chart instance, the plugin options must be set to false:

    To disable all plugins for a specific chart instance, set options.plugins to false:

    1. const chart = new Chart(ctx, {
    2. options: {
    3. plugins: false // all plugins are disabled for this instance
    4. }

    Read more about the existing plugin extension hooks.

    Chart Update

    Plugins are notified during throughout the update process.

    Chart.js update flowchart

    Plugins can interact with the chart throughout the render process. The rendering process is documented in the flowchart below. Each of the green processes is a plugin notification. The red lines indicate how cancelling part of the render process can occur when a plugin returns false from a hook. Not all hooks are cancelable, however, in general most before* hooks can be cancelled.

    Event Handling

    Plugins can interact with the chart during the event handling process. The event handling flow is documented in the flowchart below. Each of the green processes is a plugin notification. If a plugin makes changes that require a re-render, the plugin can set to true to indicate that a render is needed. The built-in tooltip plugin uses this method to indicate when the tooltip has changed.

    Chart.js event handling flowchart