Description
Check out the demo: http://codepen.io/naikus/pen/BzkoLL
SVG Gauge alternatives and similar libraries
Based on the "d3" category.
Alternatively, view SVG Gauge alternatives based on common mentions on social networks and blogs.
-
echarts
Apache ECharts is a powerful, interactive charting and data visualization library for browser -
fabric.js
Javascript Canvas Library, SVG-to-Canvas (& canvas-to-SVG) Parser -
BabylonJS
Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework. -
p5.js
p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs — -
paper.js
The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey -
Frappe Charts
Simple, responsive, modern SVG Charts with zero dependencies -
sigma.js
A JavaScript library aimed at visualizing graphs of thousands of nodes and edges -
dc.js
Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js -
mxGraph
Diagramming library that enables interactive graph and charting applications to be quickly created that run natively in any major browser that is supported by its vendor. -
rickshaw
JavaScript toolkit for creating interactive real-time graphs -
metrics-graphics
A library optimized for concise and principled data graphics and layouts. -
cubism
Cubism.js: A JavaScript library for time series visualization. -
processing.js
Processing.js makes your data visualizations work using web standards and without any plug-ins -
react-simple-maps
Beautiful React SVG maps with d3-geo and topojson using a declarative api. -
d3plus
A javascript library that extends D3.js to enable fast and beautiful visualizations. -
Bezier.js
A nodejs and client-side library for (cubic) Bezier curve work -
jquery.sparkline
A plugin for the jQuery javascript library to generate small sparkline charts directly in the browser -
Ember Charts
[Moved to: https://github.com/Addepar/ember-charts] -
uvCharts
Simple yet powerful JavaScript Charting library built using d3.js -
pykcharts.js
Well designed d3.js charting without the complexity of d3.js. -
dhtmlxSuite v.7.3.0 Standard edition
GPL version of DHTMLX Suite -
COVID-19 in Charts
Visual representations of the progression of COVID-19.
AWS Cloud-aware infrastructure-from-code toolbox [NEW]
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of SVG Gauge or a related project?
README
SVG Gauge
Minmalistic, configurable, animated SVG gauge. Zero dependencies
Buy me a coffee ☕
If you like my work please consider making a small donation
Migration from 1.0.2
The new gauge uses a viewbox of 100x100 as opposed to previous 1000x1000. All the stroke and font values have to be adjusted accordingly in your CSS. Just divide those by 10
Demo
Check out the live demo for various options and styling tips for this gauge
Usage
HTML
<div id="cpuSpeed" class="gauge-container"></div>
CSS
.gauge-container {
width: 150px;
height: 150px;
display: block;
padding: 10px;
}
.gauge-container > .gauge .dial {
stroke: #eee;
stroke-width: 2;
fill: rgba(0,0,0,0);
}
.gauge-container > .gauge .value {
stroke: rgb(47, 227, 255);
stroke-width: 2;
fill: rgba(0,0,0,0);
}
.gauge-container > .gauge .value-text {
fill: rgb(47, 227, 255);
font-family: sans-serif;
font-weight: bold;
font-size: 1em;
}
Javascript
// npm install
npm install svg-gauge
// Require JS
var Gauge = require("svg-gauge");
// Standalone
var Gauge = window.Gauge;
// Create a new Gauge
var cpuGauge = Gauge(document.getElementById("cpuSpeed"), {
max: 100,
// custom label renderer
label: function(value) {
return Math.round(value) + "/" + this.max;
},
value: 50,
// Custom dial colors (Optional)
color: function(value) {
if(value < 20) {
return "#5ee432"; // green
}else if(value < 40) {
return "#fffa50"; // yellow
}else if(value < 60) {
return "#f7aa38"; // orange
}else {
return "#ef4655"; // red
}
}
});
// Set gauge value
cpuGauge.setValue(75);
// Set value and animate (value, animation duration in seconds)
cpuGauge.setValueAnimated(90, 1);
Options
Name | Description |
---|---|
dialStartAngle |
The angle in degrees to start the dial (135 ) |
dialEndAngle |
The angle in degrees to end the dial. This MUST be less than dialStartAngle (45 ) |
radius |
The radius of the gauge (40 ) |
min |
The minimum value for the gauge. This can be a negative value (0 ) |
max |
The maximum value for the gauge (100 ) |
label |
Optional function that returns a string label that will be rendered in the center. This function will be passed the current value |
showValue |
Whether to show the value at the center of the gauge (true ) |
gaugeClass |
The CSS class of the gauge (gauge ) |
dialClass |
The CSS class of the gauge's dial (dial ) |
valueDialClass |
The CSS class of the gauge's fill (value dial) (value ) |
valueClass |
The CSS class of the gauge's text (value-text ) |
color (new) |
An optional function that can return a color for current value function(value) {} |
viewBox (new) |
An optional string that specifies the crop region (0 0 100 100 ) |
That's all good, but what about React?
import React, { useEffect, useRef } from "react";
import SvgGauge from "svg-gauge";
const defaultOptions = {
animDuration: 1,
showValue: true,
initialValue: 0,
max: 100
// Put any other defaults you want. e.g. dialStartAngle, dialEndAngle, radius, etc.
};
const Gauge = props => {
const gaugeEl = useRef(null);
const gaugeRef = useRef(null);
useEffect(() => {
if (!gaugeRef.current) {
const options = { ...defaultOptions, ...props };
gaugeRef.current = SvgGauge(gaugeEl.current, options);
gaugeRef.current.setValue(options.initialValue);
}
gaugeRef.current.setValueAnimated(props.value, 1);
}, [props]);
return <div ref={gaugeEl} className="gauge-container" />;
};
export default Gauge;
// to render:
const renderGauge = () => (
<Gauge
value={42}
// any other options you want
/>
);
React w/ TypeScript?
import { useEffect, useRef } from 'react'
import SvgGauge, { GaugeOptions, GaugeInstance } from 'svg-gauge'
const Gauge = ({ value }: Props) => {
const gaugeEl = useRef<HTMLDivElement>(null)
const gaugeRef = useRef<GaugeInstance | null>(null)
useEffect(() => {
if (!gaugeRef.current) {
if (!gaugeEl.current) return
const options: GaugeOptions = { color: value => (value < 30 ? 'green' : 'red') }
gaugeRef.current = SvgGauge(gaugeEl.current, options)
gaugeRef.current?.setValue(1)
}
gaugeRef.current?.setValueAnimated(value, 1)
}, [value])
return (
<div style={{ width: '500px', height: '500px' }}>
<div ref={gaugeEl} />
</div>
)
}
interface Props {
value: number
}
export default Gauge