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-barchart

v1.5.12

Published

A bar chart provides a way of showing data values represented as vertical bars using Chart.js module

Downloads

68

Readme

BarChart

A React component for rendering bar charts using Chart.js, with additional features to maintain consistent label widths across multiple charts.

Horizontal Bar chart with fixed label width

Installation

You can install this package using npm or yarn:

npm install chartjs-barchart

or

yarn add chartjs-barchart

Features

Chart.js bar charts don't provide a built-in feature to set a fixed label width, which can lead to inconsistent widths and heights when displaying multiple charts. This component addresses these issues by allowing you to set a consistent label width, ensuring uniformity across all your charts.

Usage

First, import the BarChart component into your React application:

Note

When the type prop is set to "vertical", the labelWidth and labelTextLength props will not be applied, as they are specific to horizontal bar charts.

import React from 'react';
import BarChart from 'chartjs-barchart';

const App = () => {
  const data = {
    labels: ['Label 1', 'Label 2', 'Label 3'],
    datasets: [
      {
        label: 'Dataset 1',
        data: [10, 20, 30],
        backgroundColor: 'rgba(75, 192, 192, 0.6)',
      },
    ],
  };

  const options = {
    scales: {
      x: {
        beginAtZero: true,
      },
    },
  };

  return (
    <div>
      <h1>Bar Chart</h1>
      <BarChart
        data={data}
        options={options}
        labelWidth={300}
        labelTextLength={10}
        type="horizontal" // Can be "horizontal" or "vertical"
      />
    </div>
  );
};

export default App;

Props

The BarChart component accepts the following props:

  • data (required): The chart data, structured as per Chart.js documentation.
  • options (optional): Custom options for the chart, structured as per Chart.js documentation.
  • labelWidth (optional): Custom width for the labels on the y-axis. Default is 400.
  • labelTextLength (optional): Specify the maximum length allowed for labels. If a label exceeds this length, it will automatically wrap onto the next line..
  • type (optional): Specifies the type of bar chart. Can be "horizontal" or "vertical". Default is "vertical".
  • rest (optional): Any additional props will be passed to the canvas element.