1.2.0 • Published 2 years ago

react-chartlet v1.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

React Chartlet

npm version minified size

A dead simple and tiny React charting library

Installation

yarn add react-chartlet

Supported Charts

  • Sparkline
  • Pie
  • Bar
  • Line

Examples

Please note that all charts are responsive by default; they will grow to fill the width of their container, and have height set to 100%. You can set a specific size on them, however if you don't your chart may not show up due to it's height being 0.

Sparkline

import { Sparkline } from 'react-chartlet'

const YourPage = () => (
  <Sparkline
    data={[2, 5, 3, 8, 1]}
    height="100px"
  />
)

export default YourPage

Donut

import { Donut } from 'react-chartlet'

const MyPage = () => (
  <Donut
    data={[2, 5, 3]}
    height="100px"
  />
)

Legend

import { Donut, Legend } from 'react-chartlet'

const MyPage = () => {
  const data = [
    { label: 'Carrots', value: 3 },
    { label: 'Tomatoes', value: 5 },
    { label: 'Potatoes', value: 2 },
  ]
  return (
    <div style={{ display: 'flex', gap: '2em' }}>
      <Donut
        data={data.map(row => row.value)}
        height="100px"
      />
      <Legend
        data={data.map(row => row.value)}
        labels={data.map(row => row.label)}
      />
    </div>
  )
}

export default YourPage

API Reference

Sparkline

PropertyTypeDefaultDescription
dataarray[]An array of numbers
widthstring-CSS width of your chart
heightstring100%CSS height of your chart
minnumbersmallest datapoint in data arrayThe minimum value on the y axis
maxnumberlargest datapoint in data arrayThe maximum value on the y axis
marginnumber or object{ top: 5, bottom: 5 }Margin between the border of the chart and the line, either as a number to set all sides, or an object to set specific sides, like { top: 5, right: 5, bottom: 5, left: 5 }
styleobject{}Directly set the style object of the svg container
lineStyleobject{}Set the style object of the line
tooltipobject{}An object with two functions, handle and close

Donut

PropertyTypeDefaultDescription
dataarray[]An array of numbers
widthstring-CSS width of your chart
heightstring100%CSS height of your chart
colorsarrayThe colors.CATEGORICAL paletteCSS colours used for each data point
styleobject{}Directly set the style object of the svg container
offsetnumber0Set the rotation offset between 0 and 1
holenumber0.5Donut hole size as a portion of the diameter
segmentStyleobject{}Set the style object of all donut segments
segmentStylesarray-Set the styles used for each donut segments

Legend

PropertyTypeDefaultDescription
dataarray[]An array of numbers, should match your chart
labelsarray[]An array of strings, in the same order as your data array
colorsarraythe colors.CATEGORICAL paletteCSS colours used for each data point
bulletSizestring15pxThe size of the colour bullets
labelStyleobject{}Set the style object of all labels
percentageStyleobject{}Set the style object of all percentage labels

Development

To test the components in this library, follow the steps below:

  1. Clone the repo onto your machine
  2. Run yarn to install dependencies
  3. Run yarn storybook to start Storybook

You can set up stories to test components using this documentation

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago