1.0.0 • Published 1 year ago

react-advanced-gauge-chart v1.0.0

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

react-advanced-gauge-chart

React component for displaying a gauge chart, using D3.js

Usage

Install it by running npm install react-advanced-gauge-chart. Then to use it:

import GaugeChart from 'react-advanced-gauge-chart'

<GaugeChart id="gauge-chart1" />

Note: This repo has been cloned and modified from https://github.com/Martin36/react-gauge-chart, please refer and use Martin's original package if you do not need the additional changes.

Important: Font Awesome Icon package should be imported (from any of your preferred CDN) in index.html.

Examples

Check the demo below for complete list of live examples of the charts

To create a default chart

<GaugeChart id="gauge-chart1" />

Chart with difference highlighted

<GaugeChart id="gauge-chart2"
  percent={0.86}
  previousValue={0.75}
/>

Demo

https://srujithm.github.io/react-advanced-gauge-chart/

API

Warning: Do not use the same id for multiple charts, as it will put multiple charts in the same container

Props from https://github.com/Martin36/react-gauge-chart:

NamePropTypeDescriptionDefault value
idPropTypes.string.isRequiredUsed for the identification of the div surrounding the chart
classNamePropTypes.stringAdd className to the div container
stylePropTypes.objectAdd style to the div container{ width: '100%' }
marginInPercentPropTypes.numberMargin for the chart inside the containing SVG element0.05
cornerRadiusPropTypes.numberCorner radius for the elements in the chart6
nrOfLevelsPropTypes.numberThe number of elements displayed in the arc3
percentPropTypes.numberThe number where the pointer should point to (between 0 and 1)0.4
arcPaddingPropTypes.numberThe distance between the elements in the arc0.05
arcWidthPropTypes.numberThe thickness of the arc0.2
colorsPropTypes.arrayAn array of colors in HEX format displayed in the arc"#00FF00", "#FF0000"
textColorPropTypes.stringThe color of the text"#FFFFFF"
needleColorPropTypes.stringThe color of the needle triangle"#464A4F"
needleBaseColorPropTypes.stringThe color of the circle at the base of the needle"#464A4F"
hideTextPropTypes.boolWhether or not to hide the percentage displayfalse
arcsLengthPropTypes.arrayAn array specifying the lenght of the each individual arc. If this prop is then the nrOfLevels prop will have no effectnone
animatePropTypes.boolWhether or not to animate the needle when loadedtrue
animDelayPropTypes.numberDelay in ms before start the needle animation500
formatTextValuePropTypes.funcFormat you own text value (example: value => value+'%')null

Newly introduced props for the chart:

NamePropTypeDescriptionDefault value
previousValuePropTypes.numberThe number to compare current percentage with (between 0 and 1)