Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bpk-component-barchart

Package Overview
Dependencies
Maintainers
5
Versions
468
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bpk-component-barchart

Backpack bar chart component.

  • 4.2.15
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
471
increased by9320%
Maintainers
5
Weekly downloads
 
Created
Source

bpk-component-barchart

Backpack bar chart component.

Installation

npm install bpk-component-barchart --save-dev

Usage

import React from 'react';
import BpkBarchart from 'bpk-component-barchart';

const priceData = [
  {
    day: 'mon',
    price: 240,
  },
  // ...
];

export default () => (
  <BpkBarchart
    xAxisLabel="Weekday"
    yAxisLabel="Price (£)"
    xScaleDataKey="day"
    yScaleDataKey="price"
    initialWidth={500}
    initialHeight={300}
    data={priceData}
  />
);

Props

PropertyPropTypeRequiredDefault Value
datacustom(validates usage of scale keys)true-
xScaleDataKeystringtrue-
yScaleDataKeystringtrue-
xAxisLabelstringtrue-
yAxisLabelstringtrue-
initialWidthnumbertrue-
initialHeightnumbertrue-
classNamestringfalsenull
leadingScrollIndicatorClassNamestringfalsenull
trailingScrollIndicatorClassNamestringfalsenull
outlierPercentagenumberfalsenull
showGridlinesboolfalsefalse
xAxisMarginnumberfalse3
xAxisTickValuefuncfalseidentity
xAxisTickOffsetnumberfalse0
xAxisTickEverynumberfalse1
yAxisMarginnumberfalse2.625
yAxisTickValuefuncfalseidentity
yAxisNumTicksnumberfalsenull
yAxisDomainarrayfalseCalculated by component
onBarClickfuncfalsenull
onBarHoverfuncfalsenull
onBarFocusfuncfalsenull
getBarLabelfuncfalseSee prop details
getBarSelectionfuncfalseSee prop details
BarComponentelementTypefalseBpkBarchartBar
disableDataTableboolfalsefalse

Theme Props

  • barchartBarBackgroundColor
  • barchartBarHoverBackgroundColor
  • barchartBarActiveBackgroundColor
  • barchartBarSelectedBackgroundColor

Prop Details

data

An array of data points with a value for the x axis and y axis respectively. The keys for the x axis and y axis can be anything you choose. Specify the keys with the props xScaleDataKey and yScaleDataKey. For this data the xScaleDataKey would be day and the yScaleDataKey price.

[
  {
    "day": "mon",
    "price": 240
  },
  {
    "day": "tus",
    "price": 340
  },
  {
    "day": "wen",
    "price": 300
  },
  {
    "day": "thu",
    "price": 340
  },
  {
    "day": "fri",
    "price": 353
  },
  {
    "day": "sat",
    "price": 290
  },
  {
    "day": "sun",
    "price": 380
  }
]
xScaleDataKey

The key in each data point that holds the value for the x axis of that data point.

yScaleDataKey

The key in each data point that holds the value for the y axis of that data point.

yAxisDomain

Override the default y axis domain. This is an array with two elements, the lower then upper domain. If either value is set to null the default value is used instead.

<BpkBarchart
  ...
  yAxisDomain={[null, 100]} // The y axis will go from 0 (the default) to 100.
/>
outlierPercentage

Values that are outlierPercentage percent above the mean of the whole dataset are considered outliers and rendered cut off instead of at their full height.

onBarClick
const onBarClick = (event, {
  point: <Object>, // The `data` array object from the bar clicked
}) => {
  ...
}
onBarHover
const onBarHover = (event, {
  point: <Object>, // The `data` array object from the bar hovered
}) => {
  ...
}
onBarFocus
const onBarFocus = (event, {
  point: <Object>, // The `data` array object from the bar focused
}) => {
  ...
}
getBarLabel

By default the following function is used:

(point, xScaleDataKey, yScaleDataKey) => {
  return `${point[xScaleDataKey]} - ${point[yScaleDataKey]}`;
}
getBarSelection

Must be a function which returns true based on the point argument:

const getBarSelection = (point) => {
  return point.myKnownProperty === 'foo';
}

FAQs

Package last updated on 29 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc