4.2.9 • Published 2 years ago

bpk-component-barchart-css v4.2.9

Weekly downloads
194
License
Apache-2.0
Repository
github
Last release
2 years ago

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';
}
4.2.9

2 years ago

4.2.5

2 years ago

4.2.7

2 years ago

4.2.2

2 years ago

4.2.4

2 years ago

4.2.1

2 years ago

4.1.11

2 years ago

4.1.17

2 years ago

4.1.12

2 years ago

4.1.14

2 years ago

4.1.4

2 years ago

4.1.3

2 years ago

4.1.6

2 years ago

4.1.2

2 years ago

4.0.15

3 years ago

4.0.12

3 years ago

4.0.10

3 years ago

4.0.9

3 years ago

4.0.8

3 years ago

4.0.7

3 years ago

4.0.6

3 years ago

4.0.5

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

3.2.6

3 years ago

4.0.0

3 years ago

3.2.8

3 years ago

3.2.5

3 years ago

3.2.4

3 years ago

3.2.3

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.48

3 years ago

3.1.47

3 years ago

3.1.46

3 years ago

3.1.45

3 years ago

3.1.44

3 years ago

3.1.43

3 years ago

3.1.41

3 years ago

3.1.40

3 years ago

3.1.42

3 years ago

3.1.39

3 years ago

3.1.38

3 years ago

3.1.36

3 years ago

3.1.37

3 years ago

3.1.35

3 years ago

3.1.34

3 years ago

3.1.33

3 years ago

3.1.32

3 years ago

3.1.31

3 years ago

3.1.30

3 years ago

3.1.29

3 years ago

3.1.28

3 years ago

3.1.27

3 years ago

3.1.26

3 years ago

3.1.25

3 years ago

3.1.24

3 years ago

3.1.23

3 years ago

3.1.22

3 years ago

3.1.21

3 years ago

3.1.20

3 years ago

3.1.18

3 years ago

3.1.19

3 years ago

3.1.15

3 years ago

3.1.14

3 years ago

3.1.13

3 years ago

3.1.12

4 years ago

3.1.11

4 years ago

3.1.9

4 years ago

3.1.8

4 years ago

3.1.7

4 years ago

3.1.6

4 years ago

3.1.5

4 years ago

3.1.4

4 years ago

3.1.3

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.78

4 years ago

3.0.73

4 years ago

3.0.71

4 years ago

3.0.70

4 years ago

3.0.68

4 years ago

3.0.67

4 years ago

3.0.66

4 years ago

3.0.65

4 years ago