1.1.0 • Published 1 year ago

react-svg-bar-chart v1.1.0

Weekly downloads
28
License
MIT
Repository
github
Last release
1 year ago

react-svg-bar-chart

npm package Travis Codecov Module formats

A lightweight responsive bar chart component for React using SVG

Getting started

react-svg-bar-chart

You can download react-svg-bar-chart from the NPM registry via the npm or yarn commands

yarn add react-svg-bar-chart
npm install react-svg-bar-chart --save

If you don't use package manager and you want to include react-svg-bar-chart directly in your html, you could get it from the UNPKG CDN

https://unpkg.com/react-svg-bar-chart/umd/react-svg-bar-chart.js

Demo

See Demo page

Usage

import React from "react"
import BarChart from "react-svg-bar-chart"

const data = []

for (let x = 1; x <= 30; x++) {
    data.push({x: x, y: Math.floor(Math.random() * 100)})
}

const MyComponent = () => (
    <BarChart data={data} onHover={this.handlePointHover} />
)

Props

NamePropTypeDescriptionDefault
areaColorStringArea color (hex, rgb...)"#34495e"
areaOpacityNumberArea opacity.5
areaVisibleBooleanArea visibilityfalse
axisColorNumberAxis color"#34495e"
axisOpacityNumberAxis opacity.5
axisVisibleBooleanAxis visibilitytrue
axisWidthNumberAxis width1
barsColorStringBars color"#34495e"
barsOpacityNumberBars opacity1
barsMarginNumberBars margin left and right (> 0 && <= 0.5)0.1
dataArray of data Objectsdata is {x: number, y: number, active: bool})[]
gridColorStringGrid color"#34495e"
gridOpacityNumberGrid color.5
gridVisibleBooleanGrid visibilitytrue
gridWidthNumberGrid width1
labelsCharacterWidthNumberLabels character with (depending on your font) to calculate the width of Y labels10
labelsColorStringLabels color"#34495e"
labelsCountYNumberY labels count5
labelsFormatXFunctionCustom X labelsx => x
labelsFormatYFunctionCustom Y labelsy => y
labelsHeightXNumberX labels height (depending on your font)12
labelsOffsetXNumberX labels offset15
labelsOffsetYNumberY labels offset15
labelsStepXNumberX labels step1
labelsVisibleNumberLabels visibilitytrue
pathWidthNumberPath width1
pointsColorStringPoints color"#fff"
pointsIsHoverOnZoneBooleanonHover function callback called on zone hover instead of points hoverfalse
onClickFunctionCallback when one bar is click(point, event) => {}
onHoverFunctionCallback when one point is hovered(point, event) => {}
pointsRadiusNumberPoints radius4
pointsStrokeColorStringPoints stroke color"#34495e"
pointsStrokeWidthNumberPoints stroke width2
pointsVisibleBooleanPoints visibilityfalse
viewBoxHeightNumberSVG viewport height300
viewBoxWidthNumberSVG viewport width800

Contributing

  • ⇄ Pull/Merge requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests (npm test).

See CONTRIBUTING.md guidelines

Changelog

See changelog

License

This project is licensed under the MIT License - see the LICENCE.md file for details

1.1.0

1 year ago

1.0.0

6 years ago