New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

gauge-chart-js

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gauge-chart-js

A tiny library for rendering gauge charts. Supports conical/polar gradients, animation timing functions, custom labels/tooltips.

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

gauge-chart-js NPM version Build Status code style: prettier

A tiny (<2kb gzipped) library for rendering gauge charts. Supports conical/polar gradients, animation timing functions, custom labels/tooltips. No external dependencies required.

Examples

Conical / Polar gradientMultiple gaugesCountdown circle

These are GIFs, therefore FPS is low.

Installation

npm install gauge-chart-js

Basic usage

import { cubicBezier, Gauge } from 'gauge-chart-js';

const gauge = new Gauge({
  container: document.querySelector('.root'),
  color: '#0f0'
});

gauge.setValue(50);

Customise easing

import { cubicBezier, Gauge } from 'gauge-chart-js';

const easeIn = cubicBezier(0, 0, 0.2, 1);
const gauge = new Gauge({
  ...
  easing: easeIn
})

Easing functions cheat sheet: https://cubic-bezier.com/#.17,.67,.83,.67

Options

NameDescriptionRequiredDefault valueType
containerThe HTML element that act as a container for the gaugeYes-HTMLElement
fromAngleGauge start angle in degreesNo220number
toAngleGauge end angle in degreesNo500number
animationDurationAnimation duration in millisecondsNo600number
animationDelayAnimation delay in milliseconds. Pass 0 for no animation.No0number
lineWidthThickness of the gaugeNo3.5number
easingThe easing function that will be used when animatingNolinear(timeFraction: number) => number
gaugeRadiusGauge radiusNo35number
colorGauge color supported by SVG's fill attributeNo-string
colorsGauge colors supported by SVG's fill attributeNo-string[]

Programmatic API

Available methods:

  • setValue(value) Sets chart value.
  • getElementAtValue(value) Returns SVG element for given value with additional information: angle and relative position to its parent container.
  • insertAdjacentToRoot(where, html) Inserts HTML to SVG root. Can be used for custom labels.
  • dispose() Disposes chart.

How to integrate it with framework X?

The library is framework-agnostic and do not require any framework-specific integration. If you are using Angular make sure chart is rendered outside zone.js:

class ExampleComponent implements OnInit {
  constructor(private ngZone: NgZone) {}

  ngOnInit() {
    const gauge = new Gauge({ ... });
    this.ngZone.runOutsideAngular(() => {
      gauge.draw();
    });
  }
}

Run examples:

  • cd examples
  • npm run example conical-gradient/conical-gradient.html
  • npm run example countdown-gauge/countdown-gauge.html
  • npm run example multiple-gauges/multiple-gauges.html

Keywords

gauge

FAQs

Package last updated on 25 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts