antoniolago / react-gauge-component

React gauge component for data visualization.
https://antoniolago.github.io/react-gauge-component/
MIT License
132 stars 19 forks source link

react-gauge-component

React Gauge Chart Component for data visualization.

This is forked from @Martin36/react-gauge-chart 0b24a45. Key differences:

Demo

https://antoniolago.github.io/react-gauge-component/

Usage

Install it by running npm install react-gauge-component --save or yarn add react-gauge-component. Then to use it:

import GaugeComponent from 'react-gauge-component';
//or
import { GaugeComponent } from 'react-gauge-component';

//Component with default values
<GaugeComponent />

For next.js you'll have to do dynamic import:

import dynamic from "next/dynamic";
const GaugeComponent = dynamic(() => import('react-gauge-component'), { ssr: false });

//Component with default values
<GaugeComponent />

Examples

Simple Gauge.

Image of Simple Grafana Gauge Component for a simple data visualization

Show Simple Gauge code ### Simple Gauge ```jsx ```

Custom Bandwidth Gauge.

Image of Gauge Component for bandwidth visualization

Show Bandwidth Gauge code ### Bandwidth Gauge ```jsx const kbitsToMbits = (value) => { if (value >= 1000) { value = value / 1000; if (Number.isInteger(value)) { return value.toFixed(0) + ' mbit/s'; } else { return value.toFixed(1) + ' mbit/s'; } } else { return value.toFixed(0) + ' kbit/s'; } } ```

Custom Temperature Gauge

Image of React Gauge Component for temperature visualization

Show Temperature Gauge code ### Temperature Gauge ```jsx console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"), onMouseMove: () => console.log("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"), onMouseLeave: () => console.log("CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"), }, { limit: 17, color: '#F5CD19', showTick: true, tooltip: { text: 'Low temperature!' } }, { limit: 28, color: '#5BE12C', showTick: true, tooltip: { text: 'OK temperature!' } }, { limit: 30, color: '#F5CD19', showTick: true, tooltip: { text: 'High temperature!' } }, { color: '#EA4228', tooltip: { text: 'Too high temperature!' } } ] }} pointer={{ color: '#345243', length: 0.80, width: 15, // elastic: true, }} labels={{ valueLabel: { formatTextValue: value => value + 'ºC' }, tickLabels: { type: 'outer', valueConfig: { formatTextValue: value => value + 'ºC', fontSize: 10 }, ticks: [ { value: 13 }, { value: 22.5 }, { value: 32 } ], } }} value={22.5} minValue={10} maxValue={35} /> ```

Gauge with blob.

Image of Blob Gauge Component for a simple data visualization

Show Gauge with blob code ### Custom gauge with blob ```jsx ```

Gradient with arrow gauge.

Image of Gradient with Arrow Gauge Component for a simple data visualization

Show Gradient with arrow code ### Custom gradient with arrow ```jsx ```

Custom radial gauge.

Image of Radial Gauge Component for a simple data visualization

Show Custom Radial Gauge code ### Custom Radial Gauge ```jsx ```

API

Props:

##### Colors for the chart The 'colorArray' prop could either be specified as an array of hex color values, such as `["#FF0000", "#00FF00", "#0000FF"]` where each arc would a color in the array (colors are assigned from left to right). If that is the case, then the **length of the array** must match the **number of levels** in the arc. If the number of colors does not match the number of levels, then the **first** and the **last** color from the colors array will be selected and the arcs will get colors that are interpolated between those. The interpolation is done using [d3.interpolateHsl](https://github.com/d3/d3-interpolate#interpolateHsl).