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

@willjw3/simple-bar-chart

v1.1.13

Published

*A React component library that lets you easily insert bar charts into your web app just by passing in a handful of parameters*

Downloads

12

Readme

Simple Bar Chart

A React component library that lets you easily insert bar charts into your web app just by passing in a handful of parameters

Installation

npm install @willjw3/simple-bar-chart

This library uses styled components. If you use the @willjw3/simple-bar-chart library in a Gatsby site, you'll need to add the plugin called gatsby-plugin-styled-components

Example Usage There are four chart components available for use:

  • BarChart is the most basic component. It displays a simple bar chart with n bars, spaced apart by a user-chosen interval.
  • BarChartNeg also displays a simple bar chart with n bars spaced apart evenly, but negative values are also allowed.
  • BarChartLinear displays a simple bar chart with bars displayed across a continuous interval.
  • BarChartLinearNeg displays a simple bar chart with bars displayed across a continuous interval, and allows negative values.
  1. Import the desired component
import { BarChartLinear } from "@willjw3/simple-bar-chart"
  1. Pass setting parameters as props
<BarChartLinear
    horizontal={years} 
    vertical={temps}
    margin={{
        top: 90,
        bottom: 60,
        right: 60,
        left: 60
    }}
    width={800}
    height={400}
    barColor={`lightgreen`}
    barBorder={`black`}
    spaceBetween={.1}
    horizontalText={{text: "Year (Starting from 1895)", color: "lightblue", space: 20, fromLeft: 300}}
    verticalText={{text: "Average Temperature", color: "lightblue", space: 15, fromTop: -350}}
    setMin={[false, 0]}
    title={{text: globaldata.description.title + " in " + globaldata.description.units, color: "lightblue", fromLeft: 150}}
    chartBackground={"gray"}
    tooltip={{x: "Year", y: "Avg. Temperature", background: "lightsteelblue", color: "black", opacity: "0.7", width: "160px", height: "30px", xshift: 18, yshift: 44}}
/>
  1. Wrap chart components in a div for controlling size, placement, etc... Widths and heights aren't automatically adjusted based on screen size, so you'll have to use this div for resizing.

Passed props in the above example:

  • horizontal - array of values defining the horizontal displacement from the y-axis of each bar.
  • vertical - array of values defining the height of each bar with its base on the x-axis. In this example, years and temps would be arrays created from data brought into the app from an external api. It's up to you to get the data into these arrays.
  • margin - space between the edge of the canvas (chart background) and the content of the chart, including labels.
  • width and height are for the chart canvas.
  • barColor - color of bars in the chart.
  • barBorder - outline color of bars. Set to 'transparent' for no outline.
  • spaceBetween - sets the amount of space between bars for barChart and barChartNeg charts. Ranges from 0 to 1 with 0 being no space and 1 being the maximum space.
  • horizontalText is for the x-axis label and
  • verticalText is for the y-axis label. The space property affects the movement of the text in a direction perpendicular to its associated axis. fromLeft moves the text horizontally (parallel to the x-axis) and fromTop moves the text vertically (parallel to the y-axis)
  • setMin - for setting whether the minimum value on the y-axis corresponds to the value of the minimum data point or a value which the user chooses. To use the value corresponding to the minimum data point value, use setMin={[false, 0]}. To use a custom value, use setMin={[true: <your custom value>]}
  • title - the title of your chart. In this example, title.text takes values from a json object that contains the data used.
  • chartBackground is the color of the chart's background.
  • tooltip - displays data corresponding to a given bar when hovering over it. x is the horizontal axis label, y is the vertical axis label, xshift and yshift control the distance of the tooltip display from its corresponding bar in the horizontal and vertical directions, respectively.

Contribute

  • to address any problems with the library, or to suggest any improvements, follow this link and post an issue.
  • to fix any code issues or fix/improve the documentation here, submit your changes in the form of a pull request by following this link.

Author: @willjw3