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 🙏

© 2026 – Pkg Stats / Ryan Hefner

chart-png

v1.1.6

Published

🏭 A simple Chart.js to Png image converter based on node-canvas / 一个基于 node-canvas 的 Chart.js -> png 转换器

Downloads

20

Readme

Chart-Png

npm

This is a simple lib that converts a Chart.js v3(.9.1)'s configuration to a png image.

Installation

npm install chart-png

Or whatever package manager you use.

[!IMPORTANT] Cuz this lib uses the canvas package, you need to install the canvas dependencies to make it work.

Node Canvas's README

For this lib, you will only need blew dependencies (because we only produce png images):

OS | Command ----- | ----- macOS | brew install pkg-config cairo pango pixman python-setuptools Ubuntu | sudo apt-get install build-essential libcairo2-dev libpango1.0-dev Fedora | sudo yum install gcc-c++ cairo-devel pango-devel Solaris | pkgin install cairo pango pkg-config xproto renderproto kbproto xextproto OpenBSD | doas pkg_add cairo pango png Windows | See the wiki Others | See the wiki

Usage

import { ChartPng } from 'chart-png';

const config = {
  type: 'bar',
  data: {
    labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
    datasets: [{
      label: '# of Votes',
      data: [12, 19, 3, 5, 2, 3],
      backgroundColor: [
        'rgba(255, 99, 132, 0.2)',
        'rgba(54, 162, 235, 0.2)',
        'rgba(255, 206, 86, 0.2)',
        'rgba(75, 192, 192, 0.2)',
        'rgba(153, 102, 255, 0.2)',
        'rgba(255, 159, 64, 0.2)'
      ],
      borderColor: [
        'rgba(255, 99, 132, 1)',
        'rgba(54, 162, 235, 1)',
        'rgba(255, 206, 86, 1)',
        'rgba(75, 192, 192, 1)',
        'rgba(153, 102, 255, 1)',
        'rgba(255, 159, 64, 1)'
      ],
      borderWidth: 1
    }]
  },
  options: {
    // support plugins
    plugins: {
      datalabels: {
        color: 'black',
        font: {
          weight: 'bold'
        }
      }
    }
    scales: {
      y: {
        beginAtZero: true
      }
    }
  },
  plugins: {
    // inline plugins
    // Don't really use this, cuz ChartPng's options.backgroundColor has done this for you.
    beforeDraw: (chart) => {
      const ctx = chart.ctx;
      ctx.save();
      ctx.fillStyle = 'red';
      ctx.fillRect(0, 0, 100, 100);
      ctx.restore();
    }
  }
}

ChartPng(config, "chart.png", "output")

API

ChartPng(
 /**
  * The chart configuration of Chart.js v3.
  * @type {Config}
  * @see https://www.chartjs.org/docs/3.9.1/configuration/
  */
 config: Config,
 /**
  * The name of the chart to render.
  * @type {string}
  * @example "bar"
  */
 name: string,
 /**
  * The directory name to save the chart.
  * @type {string}
  * @example "chart"
  */
 dirName: string,
 options?: MainOptions,
): void

interface MainOptions {
 /**
  * Optional background color for the chart, otherwise it will be white.
  * @optional
  * @type {CanvasGradient | CanvasPattern | string}
  * @default "white"
  */
 backgroundColor?: CanvasGradient | CanvasPattern | string
 /**
  * The device pixel ratio of the chart.
  * @optional
  * @type {number}
  * @default 2
  * @see https://www.chartjs.org/docs/3.9.1/configuration/device-pixel-ratio.html
  */
 devicePixelRatio?: number
 /**
  * The font to register for the chart.
  * @type {Parameters<typeof registerFont>}
  * @optional
  * @default undefined
  * @see https://github.com/Automattic/node-canvas?tab=readme-ov-file#registerfont
  * @example
  * ```ts
  * font: ["./path/to/font.ttf", { family: "Font Family" }]
  * ```
  */
 font?: Parameters<typeof registerFont>
 /**
  * The height of the charts to render, in pixels.
  * @optional
  * @type {number}
  * @default 450
  */
 height?: number
 /**
  * The width of the charts to render, in pixels.
  * @optional
  * @type {number}
  * @default 800
  */
 width?: number
}

Parameters<typeof registerFont> = [
  path: string,
  fontFace: {
    family: string;
    weight?: string;
    style?: string;
  }
]

License

MIT License © 2024-PRESENT Xat