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-doughnutlabel-rebourne

v3.0.0-beta.4

Published

Chart.js plugin for doughnut chart to display lines of text in the center

Downloads

26,759

Readme

Chart.js Doughnut plugin to allow for lines of text in the middle

Chart.js plugin module that allows to display multiple lines of text centered in the middle area of the doughnut charts. This plugin is forked from https://github.com/ciprianciurea/chartjs-plugin-doughnutlabel to provide support for Chart.js v3 as well as some other improvements and bug fixes. This is a BREAKING change meaning this plugin will NOT work with Chart.js v3.

Demo

Have a look at the Demo page.

Table of contents

Installation

Install through yarn:

yarn install chartjs-plugin-doughnutlabel-rebourne

Don't forget to install v3 of Chart.js:

yarn install chart.js@next

After that, you need to activate the plugin, either globally :

Chart.plugins.register(DoughnutLabel);

or for each chart separately:

new Chart(ctx, {
  plugins: [DoughnutLabel],
});

Usage

Below is a table with available options:

| Option | Description | Label Scope | Plugin Scope | Global Scope | | ------------------- | -------------------------------------------------------------------------------------------------------------------------------- | :---------: | :----------: | :----------: | | paddingPercentage | add padding when scaling text larger than inner circle (defaults to 10) | | ✓ | ✓ | | labels | array of labels (objects) | | ✓ | | | color | css property | ✓ | ✓ | ✓ | | font.family | css property | ✓ | ✓ | ✓ | | font.lineHeight | css property | ✓ | ✓ | ✓ | | font.size | css property | ✓ | ✓ | ✓ | | font.style | css property | ✓ | ✓ | ✓ | | font.weight | css property | ✓ | ✓ | ✓ | | font.string | all previous font properties in one string separated by space | ✓ | ✓ | ✓ | | text | value of label (can be string or function) | ✓ | | | | display | show label or not | ✓ | ✓ | ✓ | | api* | plugin core api (defaults to beforeDatasetDraw) | | ✓ | ✓ |

*Option api is a really-low level and intended for developers and those who are familar with internal workings of Chart.js (or have experience making plugins).

Note that more specific scope will override more global. For example, if you declare color in plugin scope and in label scope, value from label scope will win.

Options with global scope have a special meaning - they will always have a default value, i.e. if other scopes have no value, the final option will taken from Chart.defaults scope.

Chart.defaults.plugins.doughnutlabel = {}; // global scope

options: {
  plugins: {
    doughnutlabel: { // plugin scope
      paddingPercentage: 5,
      labels: [
        { // label scope
          text: 'Text' or functionName,
          font: {
            size: '24',
            family: 'Arial, Helvetica, sans-serif',
            style: 'italic',
            weight: 'bold',
          },
          color: '#bc2c1a',
        },
      ],
    },
  },
},

Usage without a module bundler

Using CDN is probably the best way - jsDelivr. Select the .min file with SRI parameters for extra safety. If you need to debug any issues, select the full version instead.

Alternatively, the plugin can be manually downloaded from the Releases page on GitHub!

<script src="chartjs-plugin-doughnutlabel-rebourne.js"></script>

or use the minified version

<script src="chartjs-plugin-doughnutlabel-rebourne.min.js"></script>

Development

You first need to install node dependencies (requires Node.js):

yarn install

The following commands are available via package.json:

| Command | Purpose | | :------------------- | :---------------------------------------------- | | yarn lint | perform code linting | | yarn build | build dist files | | yarn build --watch | build and watch for changes (inc. browser-sync) | | yarn package | create an archive with dist files and samples |

License

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