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

saar-chart

v1.0.3

Published

A customizable chart component for React.

Readme

SaarChart

SaarChart is a versatile, responsive, and feature-rich React chart component built on top of Chart.js and react-chartjs-2. It supports multiple chart types, theming, accessibility features, and advanced customization options, making it easy to integrate into any React application.

Table of Contents

Features

  • Multiple Chart Types: Supports Bar, Pie, Line, Doughnut, Radar, Polar Area, and more.
  • Responsive Design: Automatically adjusts to fit the container size.
  • Customizable: Pass custom data, labels, legends, colors, and options.
  • Advanced UI/UX: Includes loading states, error handling, interactive tooltips, and animations.
  • Export Options: Allows exporting charts as images.
  • Theming Support: Adapts to light or dark themes.
  • Accessibility: Screen reader friendly and keyboard accessible.

Installation

Prerequisites

  • Node.js: Ensure you have Node.js installed (preferably the latest LTS version).
  • NPM: Comes bundled with Node.js.

Installing the Package

Install the package via NPM:

npm install saar-chart

Or via Yarn:

yarn add saar-chart

Peer Dependencies

Ensure that react, react-dom, and chart.js are also installed as peer dependencies. You can add them via:

npm install react react-dom chart.js

Usage

Basic Example

Here's a simple example of how to use the SaarChart component in your application:

import React from 'react';
import SaarChart from 'saar-chart';

const data = {
  labels: ['January', 'February', 'March', 'April', 'May'],
  datasets: [
    {
      label: 'Sales',
      data: [150, 200, 100, 250, 300],
      backgroundColor: 'rgba(75, 192, 192, 0.2)',
      borderColor: 'rgba(75, 192, 192, 1)',
      borderWidth: 1,
    },
  ],
};

const options = {
  responsive: true,
  plugins: {
    legend: {
      position: 'top',
    },
    title: {
      display: true,
      text: 'Monthly Sales Data',
    },
  },
};

const BasicChart = () => {
  return <SaarChart type="bar" data={data} options={options} />;
};

export default BasicChart;

Advanced Example

For more customization, you can pass additional props and make use of event handlers:

import React from 'react';
import SaarChart from 'saar-chart';

const advancedData = {
  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,
    },
  ],
};

const AdvancedChart = () => {
  const handleClick = (event, chartElement) => {
    if (chartElement.length > 0) {
      console.log('Clicked:', chartElement[0].index);
    }
  };

  return (
    <SaarChart
      type="doughnut"
      data={advancedData}
      options={{
        onClick: handleClick,
        plugins: {
          legend: {
            position: 'right',
          },
        },
      }}
    />
  );
};

export default AdvancedChart;

Props

  • type (string): Type of the chart (e.g., 'bar', 'line', 'pie').
  • data (object): Data for the chart.
  • options (object): Chart.js configuration options.
  • height (number): Height of the canvas element.
  • width (number): Width of the canvas element.
  • onClick (function): Event handler for chart click events.

Advanced Features

  • Loading State: Use loading prop to display a loading spinner while the chart is being loaded.
  • Error Handling: The error prop can display a fallback UI in case of any issues.
  • Animation: You can control chart animations through the options.animation parameter.

Theming Support

The SaarChart component supports theming for light and dark modes. You can pass a theme prop (light or dark) to adjust the chart styles accordingly:

<SaarChart type="bar" data={data} options={options} theme="dark" />

Accessibility

  • ARIA Support: The charts include relevant ARIA labels to enhance accessibility.
  • Keyboard Navigation: The component is built to be navigable via keyboard shortcuts.

Component Implementation

The SaarChart is implemented as a wrapper around the popular react-chartjs-2 library, which is itself a React wrapper for Chart.js. This provides full access to Chart.js features while maintaining React component conventions for state and props management.

Development

Project Structure

  • src/: Contains the main code for the SaarChart component.
  • examples/: Sample applications demonstrating how to use SaarChart.
  • tests/: Contains unit and integration tests for ensuring component quality.

Building the Package

To build the package for production, run:

npm run build

This will create a dist folder with the compiled JavaScript files ready to be published.

Troubleshooting

  • Chart Not Displaying: Make sure you have included all peer dependencies (react, chart.js).
  • Incorrect Data Display: Verify that the data structure matches Chart.js expectations.
  • Console Warnings: Ensure all required props are passed correctly to the component.

Contributing

We welcome contributions! Please see our Contributing Guide for details on how to get started.

License

This project is licensed under the MIT License. See the LICENSE file for more information.