npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chartjs-plugin-waterfall

v1.0.3

Published

Chart.js plugin for easy waterfall charts

Downloads

1,357

Readme

Installation

npm install --save chartjs-plugin-waterfall

Here's what it looks like: WaterFall Chart Example

Usage

Just import the plugin and add it to any chart that you want to be a waterfall chart like so:

import waterFallPlugin from 'chartjs-plugin-waterfall';

var chart = new Chart(ctx, {
    plugins: [waterFallPlugin]
});

See the plugins documentation for more info.

How it works

This plugin works by checking if any of your datasets contain a property called dummyStack that is set to true. The stack property must be used in conjunction with dummyStack for this plugin to work properly. If dummyStack is true then it hides the label, tooltip and sets the color invisible. When you use stacking with this it creates the affect of a floating bar as shown in the image above that we can use for waterfall charts as chartjs-2 doesn't support waterfall charts by default.

E.g:

const data = {
  datasets: [
    {
      label: 'Closing Costs',
      data: [50],
      backgroundColor: '#e8cdd7',
      stack: 'stack 1',
    },
    {
      label: 'Purchase Price',
      data: [700],
      backgroundColor: '#d29baf',
      stack: 'stack 1',
    },
    {
      data: [200],
      waterfall: {
        dummyStack: true,
      },
      stack: 'stack 2',
    },
    {
      label: 'Opening Loan Balance',
      data: [550],
      backgroundColor: '#bb6987',
      stack: 'stack 2',
    },
    {
      label: 'Initial Cash Investment',
      data: [200],
      backgroundColor: '#a53860',
      stack: 'stack 3',
    },
  ],
};

This dataset will give us the look in the image above.

Options

The plugin options can be changed at 3 different levels:

globally: Chart.defaults.global.plugins.waterfall.*

per chart: options.plugins.waterfall.*

per dataset: dataset.waterfall.* (not all options)

The default chart options are:

options: {
  plugins: {
    waterFallPlugin: {
      stepLines: {
        enabled: true,
        startColorStop: 0,
        endColorStop: 0.6,
        startColor: 'rgba(0, 0, 0, 0.55)',
        endColor: 'rgba(0, 0, 0, 0)',
        diagonalStepLines: true,
      },
    },
  },
}

Dataset options: dummyStack: (boolean) If true then hides the tooltip, legend and sets the color to transparent.

Global/Chart options:

stepLines.enabled: (boolean) If true then it shows the step-lines going from one bar to another.

Global/Chart/Dataset options:

stepLines.startColorStop: (number) Used as the offset value in the first addColorStop method call.

stepLines.startColor: (string) Used as the color value in the first addColorStop method call.

stepLines.endColorStop: (number) Used as the offset value in the second addColorStop method call.

stepLines.endColor: (string) Used as the color value in the second addColorStop method call.

For lines going from bar to bar that you need maximum customization over, see chartjs-plugin-custom-lines.

Caveats

  • Multiple values in data currently are not supported by this plugin.
  • The invisible dummy stacks are removed from the tooltip and legend by default using the filter method. If you are providing your own filter method, using a custom tooltip or legend of your own then you will have to manually hide them because it will overwrite this plugins.

E.g. This is how this plugin hides them, so you could do it this way:

  filter: function(legendItem, chartData) {
    var currentDataset = chartData.datasets[legendItem.datasetIndex];

    return !currentDataset.dummyStack;
  }