react-d3-speedometer
react-d3-speedometer is a react component for showing speedometer like gauge using d3.
Usage:
NPM:
npm install --save react-d3-speedometer
Yarn:
yarn add react-d3-speedometer
import ReactSpeedometer from "react-d3-speedometer";
<ReactSpeedometer />
Configuration Options:
prop | type | default | comments |
---|
value | number | 0 | Make sure your value is between your minValue and maxValue |
minValue | number | 0 | |
maxValue | number | 1000 | |
segments | number | 5 | Number of segments in the speedometer |
width | number | 300 | diameter of the speedometer and the width of the svg element |
height | number | 300 | height of the svg element. Height of the speedometer is always half the width since it is a semi-circle. For fluid width, please refere to fluidWidth config |
fluidWidth | boolean | false | If true takes the width of the parent component. See Live Example for more details |
needleColor | string | steelblue | Should be a valid color code - colorname, hexadecimal name or rgb value. Should be a valid input for d3.interpolateHsl |
startColor | string | #FF471A | Should be a valid color code - colorname, hexadecimal name or rgb value. Should be a valid input for d3.interpolateHsl |
endColor | string | #33CC33 | Should be a valid color code - colorname, hexadecimal name or rgb value. Should be a valid input for d3.interpolateHsl |
needleTransition | string | easeQuadInOut | d3-easing-identifiers - easeLinear, easeQuadIn, easeQuadOut, easeQuadInOut, easeCubicIn, easeCubicOut, easeCubicInOut, easePolyIn, easePolyOut, easePolyInOut, easeSinIn, easeSinOut, easeSinInOut, easeExpIn, easeExpOut, easeExpInOut, easeCircleIn, easeCircleOut, easeCircleInOut, easeBounceIn, easeBounceOut, easeBounceInOut, easeBackIn, easeBackOut, easeBackInOut, easeElasticIn, easeElasticOut, easeElasticInOut, easeElastic |
needleTransitionDuration | number | 500 | Time in milliseconds. |
ringWidth | number | 60 | Width of the speedometer ring. |
textColor | string | "#666" | Should be a valid color code - colorname, hexadecimal name or rgb value. Used for both showing the current value and the segment values |
Examples
You can view Live Examples here
Default with no config - Live Example
<ReactSpeedometer />
<ReactSpeedometer
maxValue={500}
value={473}
needleColor="red"
startColor="green"
segments={10}
endColor="blue"
/>
<div style={{
width: "500px",
height: "300px",
background: "#EFEFEF"
}}>
<ReactSpeedometer
fluidWidth={true}
minValue={100}
maxValue={500}
value={473}
needleColor="steelblue"
/>
</div>
Needle Transition Example - Live Example
<ReactSpeedometer
value={333}
needleColor="steelblue"
needleTransitionDuration={4000}
needleTransition="easeElastic"
/>
This is the needle transition used in the sample image
Todos:
Changelog:
View Changelog
Credits:
react-d3-speedometer
was started as a react port of the following d3 snippet - http://bl.ocks.org/msqr/3202712. Component template bootstrapped with React CDK. Also, many thanks to d3
and react
ecosystem contributors.
License:
MIT