Search results

Ranges in JavaScript Circular Gauge control

You can categories certain interval on gauge axis using ranges property.

Start and End

Start and end value of a range in an axis can be customized by using start and end properties.

Source
Preview
index.ts
index.html
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
    axes: [{
        ranges: [{
            start: 40,
            end: 80
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Customization

Color and thickness of the range can be customized by using color,startWidth and endWidth property.

Source
Preview
index.ts
index.html
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
    axes: [{
        ranges: [{
            start: 40,
            end: 80, endWidth: 15,
            startWidth: 15,
            color: '#ff5985'
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Radius

You can place the range inside or outside of the axis by using radius property. The radius of the range can takes value either in percentage or in pixels. By default, ranges take 100% of the axis radius.

In Pixel

You can set the radius of the range in pixel as demonstrated below,

Source
Preview
index.ts
index.html
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
    axes: [{
        minimum: 0,
        maximum: 100,
        ranges: [{
            start: 40,
            end: 80,
            radius: '100'
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

In Percentage

By setting value in percentage, range gets its dimension with respect to its axis radius. For example, when the radius is ‘50%’, range renders to half of the axis radius.

Source
Preview
index.ts
index.html
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
    axes: [{
        minimum: 0,
        maximum: 100,
        ranges: [{
            start: 40,
            end: 80,
            radius: '50%'
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Dragging Range

The ranges can be dragged over the axis line by clicking and dragging the same. To enable or disable the range drag, use the enableRangeDrag property.

Source
Preview
index.ts
index.html
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
    enableRangeDrag:true,
    height:'250px',
    width:'250px',
    axes: [{
        ranges: [{
            start: 0,
            end: 100,
            startWidth: 8, endWidth: 8,
            radius: '108%',
            color: '#30B32D'
        }],
        pointers: [{
            value: 50
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Multiple Ranges

You can add multiple ranges to an axis with the above customization as demonstrated below.

Note: You can set the range color to axis ticks and labels by enabling useRangeColor property in majorTicks, minorTicks and labelStyle object.

Source
Preview
index.ts
index.html
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
    axes: [{
        minimum: 0,
        maximum: 100,
        majorTicks: {
            useRangeColor: true
        },
        minorTicks: {
            useRangeColor: true
        },
        labelStyle: {
            useRangeColor: true
        },
        ranges: [{
            start: 0,
            end: 25,
            radius: '108%'
        },{
            start: 25,
            end: 50,
            radius: '70%'
        },{
            start: 50,
            end: 75,
            radius: '70%'
        },{
            start: 75,
            end: 100,
            radius: '108%'
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Rounded corner radius

You can customize the corner radius using the roundedCornerRadius property in ranges.

Source
Preview
index.ts
index.html
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
    axes: [{
        minimum: 0,
        maximum: 100,
        ranges: [{
            start: 40,
            end: 80,
            radius: '50%',
            roundedCornerRadius: 5,
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Gradient Color

Gradient support allows to add multiple colors in the ranges and pointers of the circular gauge. The following gradient types are supported in the circular gauge.

  • Linear Gradient
  • Radial Gradient

Linear Gradient

Using linear gradient, colors will be applied in a linear progression. The start value of the linear gradient will be set using the startValue property. The end value of the linear gradient will be set using the endValue property. The color stop values such as color, opacity and offset are set using colorStop property.

To apply linear gradient to the range, follow the below code sample.

Source
Preview
index.ts
index.html
import { CircularGauge, Gradient } from '@syncfusion/ej2-circulargauge';
CircularGauge.Inject(Gradient);
let rangeLinearGradient: Object = {
    startValue: '0%', endValue: '100%',
    colorStop: [
        { color: '#9E40DC', offset: '0%', opacity: 0.9 },
        { color: '#E63B86', offset: '70%', opacity: 0.9 }]
};
let gauge: CircularGauge = new CircularGauge({
    title: 'Short Put Distance',
    titleStyle: {
        size: '18px'
    },
    centerY: '57%',
    axes: [{
        annotations: [{
            content: '12 M', radius: '108%', angle: 98, zIndex: '1'
        }, {
            content: '11 M', radius: '80%', angle: 81, zIndex: '1'
        }, {
            content: '10 M', radius: '50%', angle: 69, zIndex: '1'
        }, {
            content: 'Doe', radius: '108%', angle: 190, zIndex: '1'
        }, {
            content: 'Almaida', radius: '80%', angle: 185, zIndex: '1'
        }, {
            content: 'John', radius: '50%', angle: 180, zIndex: '1'
        }],
        lineStyle: {
             width: 0
        },
        radius: '90%',
        labelStyle: {
            font: {
                size: '0px'
            }
        }, majorTicks: {
            width: 0,
        }, minorTicks: {
            width: 0,
        },
        startAngle: 200, endAngle: 130,
        minimum: 0, maximum: 14,
        ranges: [{
            start: 0, end: 12, radius: '115%',
            startWidth: 25, endWidth: 25,
            linearGradient : rangeLinearGradient
        }, {
            start: 0, end: 11, radius: '85%',
            startWidth: 25, endWidth: 25,
            linearGradient : rangeLinearGradient
        }, {
            start: 0, end: 10, radius: '55%',
            startWidth: 25, endWidth: 25,
            linearGradient : rangeLinearGradient
        }],
        pointers: [{
            type: 'Marker', value: 12, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/football.png',
            radius: '108%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
        }, {
            type: 'Marker', value: 11, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/basketball.png',
            radius: '78%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1200 }
        }, {
            type: 'Marker', value: 10, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/golfball.png',
            radius: '48%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 900 }
        }, {
            type: 'Marker', value: 12, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/athletics.png',
            radius: '0%', markerWidth: 90, markerHeight: 90,
            animation: { duration: 0 }
        }, {
            type: 'Marker', value: 0.1, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/girl1.png',
            radius: '108%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
        }, {
            type: 'Marker', value: 0.1, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/man1.png',
            radius: '78%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
        }, {
            type: 'Marker', value: 0.1, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/man2.png',
            radius: '48%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

Radial Gradient

Using radial gradient, colors will be applied in circular progression. The inner circle position of the radial gradient will be set using the innerPosition property. The outer circle position of the radial gradient can be set using the outerPosition property. The color stop values such as color, opacity and offset are set using colorStop property.

To apply radial gradient to the range, follow the below code sample.

Source
Preview
index.ts
index.html
import { CircularGauge, Gradient, Annotaions } from '@syncfusion/ej2-circulargauge';
CircularGauge.Inject(Gradient, Annotations);
let rangeRadialGradient: Object = {
    radius: '50%', innerPosition: { x: '50%', y: '50%' },
    outerPosition: { x: '50%', y: '50%' },
    colorStop: [
        { color: '#9E40DC', offset: '90%', opacity: 0.9 },
        { color: '#E63B86', offset: '160%', opacity: 0.9 }]
};
let gauge: CircularGauge = new CircularGauge({
    title: 'Short Put Distance',
    titleStyle: {
        size: '18px'
    },
    centerY: '57%',
    axes: [{
        annotations: [{
            content: '12 M', radius: '108%', angle: 98, zIndex: '1'
        }, {
            content: '11 M', radius: '80%', angle: 81, zIndex: '1'
        }, {
            content: '10 M', radius: '50%', angle: 69, zIndex: '1'
        }, {
            content: 'Doe', radius: '108%', angle: 190, zIndex: '1'
        }, {
            content: 'Almaida', radius: '80%', angle: 185, zIndex: '1'
        }, {
            content: 'John', radius: '50%', angle: 180, zIndex: '1'
        }],
        lineStyle: {
            width: 0
        },
        radius: '90%',
        labelStyle: {
        font: {
            size: '0px'
        }
        }, majorTicks: {
            width: 0,
        }, minorTicks: {
            width: 0,
        },
        startAngle: 200, endAngle: 130,
        minimum: 0, maximum: 14,
        ranges: [{
        start: 0, end: 12, radius: '115%',
        startWidth: 25, endWidth: 25,
        radialGradient: rangeRadialGradient
        }, {
            start: 0, end: 11, radius: '85%',
            startWidth: 25, endWidth: 25,
            radialGradient: rangeRadialGradient
        }, {
            start: 0, end: 10, radius: '55%',
            startWidth: 25, endWidth: 25,
            radialGradient: rangeRadialGradient
            }],
        pointers: [{
            type: 'Marker', value: 12, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/football.png',
            radius: '108%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
        }, {
            type: 'Marker', value: 11, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/basketball.png',
            radius: '78%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1200 }
        }, {
            type: 'Marker', value: 10, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/golfball.png',
            radius: '48%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 900 }
        }, {
            type: 'Marker', value: 12, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/athletics.png',
            radius: '0%', markerWidth: 90, markerHeight: 90,
            animation: { duration: 0 }
        }, {
            type: 'Marker', value: 0.1, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/girl1.png',
            radius: '108%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
        }, {
            type: 'Marker', value: 0.1, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/man1.png',
            radius: '78%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
         }, {
            type: 'Marker', value: 0.1, markerShape: 'Image',
            imageUrl: 'templates/circular-gauge/images/man2.png',
            radius: '48%', markerWidth: 28, markerHeight: 28,
            animation: { duration: 1500 }
        }]
    }]
}, '#element');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Animation</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container'>
        <div id='element'></div>
    </div>
</body>

</html>

See also