Gauge appearance in EJ2 TypeScript Circular gauge control
29 Aug 202316 minutes to read
Gauge Title
Circular gauge can be given a title by using title
property, to show the information about the gauge.
Title can be customized by using titleStyle
property in gauge.
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
title: 'Speedometer',
titleStyle: {
color: '#27d5ff'
}
}, '#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="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
Gauge Position
Gauge can be positioned anywhere in the container with the help of centerX
and centerY
property and it accepts values either in percentage or in pixels.
The default value of the centerX
and
centerY
property is 50%, which means gauge will get rendered to the centre of the container.
In Pixel
You can set the mid point of the gauge in pixel as demonstrated below,
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
centerX: '20',
centerY: '20',
axes: [{
lineStyle: {
width: 2,
color: '#F8F8F8'
},
startAngle: 90,
endAngle: 180
}]
}, '#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="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
In Percentage
By setting the value in percentage, gauge gets its mid point with respect to its plot area.
For example, when the centerX
value as ‘0%’ and centerY
value is ‘50%’, gauge will get positioned at the top left corner of the plot area.
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
centerX: '10%',
centerY: '50%',
axes: [{
lineStyle: {
width: 2,
color: '#F8F8F8'
},
startAngle: 0,
endAngle: 180
}]
}, '#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="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
Area Customization
Customize the gauge background
Using background
and border
properties, you can change the background color and border of the circular gauge.
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
background: 'skyblue',
//Customize the chart border and opacity.
border: {color: "#FF0000", width: 2},
axes: [{
radius: '90%',
maximum: 120,
startAngle: 230,
endAngle: 130,
majorTicks: {
width: 1, color: '#8c8c8c'
},
lineStyle: { width: 2 },
minorTicks: {
width: 1, color: '#8c8c8c'
},
pointers: [{
value: 60,
radius: '60%'
}],
ranges: [{
start: 0,
end: 70,
radius: '110%'
}, {
start: 70,
end: 110,
radius: '110%'
}, {
start: 110,
end: 120,
radius: '110%'
}]
}]
}, '#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="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
Gauge Margin
You can set margin for gauge from its container through margin
property.
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
background: 'skyblue',
//Customize the chart border and opacity.
border: {color: "#FF0000", width: 2},
//Change chart margin to left, right, top and bottom.
margin: { left: 40, right: 40, top: 40, bottom: 40 },
axes: [{
radius: '90%',
maximum: 120,
startAngle: 230,
endAngle: 130,
majorTicks: {
width: 1, color: '#8c8c8c'
},
lineStyle: { width: 2 },
minorTicks: {
width: 1, color: '#8c8c8c'
},
pointers: [{
value: 60,
radius: '60%'
}],
ranges: [{
start: 0,
end: 70,
radius: '110%'
}, {
start: 70,
end: 110,
radius: '110%'
}, {
start: 110,
end: 120,
radius: '110%'
}]
}]
}, '#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="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
Radius calculation based on angles
Render semi or quarter circular gauges by modifying the start and end angles. By enabling the radius based on angle option, the radius of circular gauge will be calculated based on the start and end angles to avoid excess white space.
import { CircularGauge } from '@syncfusion/ej2-circulargauge';
let gauge: CircularGauge = new CircularGauge({
moveToCenter: true,
axes: [{
lineStyle: {
width: 2,
color: '#F8F8F8'
},
startAngle: 270,
endAngle: 90,
radius: '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="https://cdn.syncfusion.com/ej2/27.2.2/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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>