Pointers in Circular Gauge Control

19 Dec 202224 minutes to read

Pointers are used to indicate values on the axis. Value of the pointer can be modified using the value property.

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
.Pointers(pointer => pointer.Value(90).Add()).Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Gauge supports 3 types of pointers such as Needle, RangeBar and Marker. You can choose any one of the pointer by using type property.

Needle Pointers

A needle pointer contains three parts, a needle, a cap / knob and a tail. The length of the needle can be customized by using radius property. The length of the tail can be customized by using length property. The radius of the cap can be customized by using radius in cap object. The needle and tail length takes value either in percentage or pixel.

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
.Pointers(pointer => pointer.Value(90)
                            .Radius("50%")
                            .Cap(cab => cab.Radius(10)).NeedleTail(needle => needle.Length("25%"))
        .Add())
  .Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Customization

Needle color and width can be customized by using color and pointerWidth property. Cap and tails can be customized by using cap and needleTail object.

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
.Pointers(pointer => pointer.Value(90)
                            .Radius("50%").Color("#007DD1").PointerWidth(10)
                            .Border(border => border.Color("#007DD1").Width(5))
                            .Cap(cab => cab.Radius(10).Color("white"))
                            .NeedleTail(needle => needle.Length("25%").Color("#007DD1"))
        .Add())
  .Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

The appearance of the needle pointer can be customized by using NeedleStartWidth and NeedleEndWidth.

@using Syncfusion.EJ2.CircularGauge;
@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular").Axes(axes => axes.StartAngle(270).EndAngle(90).Minimum(0).Maximum(100)
.Pointers(pointer => pointer.Value(70)
                            .Radius("80%").Color("green").PointerWidth(2).NeedleStartWidth(4).NeedleEndWidth(4)
                            .Animation(animation => animation.Enable(true).Duration(1000))
                            .Cap(cab => cab.Radius(8).Color("Green"))
                            .NeedleTail(needle => needle.Length("0%"))
        .Add()).LineStyle(l => l.Width(3).Color("#1E7145")).MajorTicks(mjt => mjt.Width(1).Height(0).Interval(100))
        .MinorTicks(mit => mit.Width(0).Height(0)).Annotations(annotation => annotation.Angle(180).ZIndex("1").Radius("20%")
 .Content("#template").Add())
        .LabelStyle(ls => ls.Position(Position.Outside).Font(new CircularGaugeFont { Color = "#1E7145", Size = "0px" }))
  .Add()).Render()

<script id='template' type="text/x-template">
    <div id='templateWrap'>
        <div class='des'>
            <div style="color:#757575; font-family:Roboto; font-size:14px;padding-top: 26px">Customized Needle</div>
        </div>
    </div>
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

RangeBar Pointer

RangeBar pointer is like ranges in an axis, that can be placed on gauge to mark the pointer value. RangeBar starts from the beginning of the gauge and ends at the pointer value.

@using Syncfusion.EJ2;

@using Syncfusion.EJ2.CircularGauge;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
 .Pointers(pointer => pointer.Value(50).Type(PointerType.RangeBar).Radius("50%").Add())
.Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Customization

RangeBar can be customized in terms of color, border and thickness by using color, border and pointerWidth property.

@using Syncfusion.EJ2.CircularGauge;
@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
 .Pointers(pointer => pointer.Value(50).Type(PointerType.RangeBar).Radius("50%")
 .Color("#007DD1").PointerWidth(15)
 .Border(border =>border.Color("grey").Width(2)).Add())
.Add()).Render()
using Microsoft.AspNetCore.Mvc;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Rounded corner for range bar pointer

The start and end pointers of range bar in the circular gauge are rounded to form arc gauges.

@using Syncfusion.EJ2.CircularGauge;
@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
 .Pointers(pointer => pointer.Value(50).Type(PointerType.RangeBar)
 .Radius("50%").RoundedCornerRadius(6).Add())
.Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Marker Pointer

Different type of marker shape can be used to mark the pointer value in axis. You can change the marker shape using markerShape property in pointer. Gauge supports the below marker shape.

  • Circle
  • Rectangle
  • Triangle
  • InvertedTriangle
  • Diamond

The image can be used instead of rendering marker shape to denote the pointer value. It can be achieved by setting markerShape to Image and assigning  image path to imageUrl in pointer.

@using Syncfusion.EJ2;
@using Syncfusion.EJ2.CircularGauge;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
 .Pointers(pointer => pointer.Value(50).Type(PointerType.Marker)
 .Radius("100%").MarkerShape(GaugeShape.InvertedTriangle).MarkerWidth(15).MarkerHeight(15).Add())
.Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Customization

The marker can be customized in terms of color, border, width and height by using color, border, markerWidth and markerHeight property in pointer.

@using Syncfusion.EJ2;
@using Syncfusion.EJ2.CircularGauge;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
 .Pointers(pointer => pointer.Value(50).Type(PointerType.Marker).Color("white")
                      .Border(border =>border.Color("#007DD1").Width(2))
 .Radius("100%").MarkerShape(GaugeShape.InvertedTriangle).MarkerWidth(15).MarkerHeight(15).Add())
.Add()).Render()
using Microsoft.AspNetCore.Mvc;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Dragging Pointer

The pointers can be dragged over the axis line by clicking and dragging the same. To enable or disable the pointer drag, use the EnablePointerDrag property.

@using Syncfusion.EJ2;
@Html.EJS().CircularGauge("circular").Height("250px").Width("250px").EnablePointerDrag(true).Axes(axes => axes
.Pointers(pointer => pointer.Value(50)
        .Add())
  .Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Multiple Pointers

In addition to the default pointer, you can add n number of pointer to an axis by using pointers property.

@using Syncfusion.EJ2;
@using Syncfusion.EJ2.CircularGauge;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
 .Pointers(pointer => {
     pointer.Value(90).Type(PointerType.Marker)
     .Radius("100%").MarkerShape(GaugeShape.Triangle).MarkerWidth(15).MarkerHeight(15).Add();
     pointer.Value(90).Type(PointerType.RangeBar).Radius("60%").PointerWidth(10).Add();
     pointer.Value(90).NeedleTail(nt => nt.Length("22%")).PointerWidth(20)
         .Cap(cap => cap.Radius(15).Border(border => border.Width(5))).Radius("60%").Add();
 })
.Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Animation

Pointer will get animate on loading the gauge, this can be handled by using animation property in pointer. The enable property in animation allows to enable or disable the animation. The duration property specifies the duration of the animation in milliseconds.

@using Syncfusion.EJ2;
@using Syncfusion.EJ2.CircularGauge;

@Html.EJS().CircularGauge("circular").Axes(axes => axes
 .Pointers(pointer => {
     pointer.Value(90).Type(PointerType.Marker).Animation(animation => animation.Enable(true).Duration(500))
     .Radius("100%").MarkerShape(GaugeShape.Triangle).MarkerWidth(15).MarkerHeight(15).Add();
     pointer.Value(90).Type(PointerType.RangeBar).Radius("60%").PointerWidth(10).Add();
     pointer.Value(90).NeedleTail(nt => nt.Length("22%")).PointerWidth(20)
         .Cap(cap => cap.Radius(15).Border(border => border.Width(5))).Radius("60%").Add();
 })
.Add()).Render()
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

Gradient Color

Gradient support allows to add multiple colors in the range and pointer 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.

The linear gradient can be applied to all pointer types like marker, range bar and needle.

@using Syncfusion.EJ2.CircularGauge;
@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("container").Load("onGaugeLoad").Axes(axes => axes.Radius("90%").StartAngle(270).EndAngle(90)
                   .LineStyle(new CircularGaugeLine{ Width = 3, Color = "#E63B86" }).LabelStyle(new CircularGaugeLabel
                   {
                       Font = new CircularGaugeFont { Size = "0px" }
                   }).MajorTicks(new CircularGaugeTick
                   {
                       Height = 0,
                       Color = "transparent"
                   })
                   .MinorTicks(new CircularGaugeTick
                   {
                       Height = 0,
                       Color = "transparent"
                   }).Minimum(0).Maximum(100).Add()).Render()

<script>
    var pointerLinearGradient = {
        startValue: '0%',
        endValue: '100%',
        colorStop: [
              { color: '#FEF3F9', offset: '0%', opacity: 0.9 },
              { color: '#E63B86', offset: '70%', opacity: 0.9 }]
    } 
    function onGaugeLoad(sender) {
        sender.gauge.axes[0].pointers = [{
            radius: '80%',
            value: 80,
            animation: { enable: true, duration: 1000 },
            pointerWidth: 10,
            linearGradient: pointerLinearGradient,
            cap: {
                radius: 8,
                color: 'white',
                border: {
                    color: '#E63B86',
                    width: 1
                }
                },
            needleTail: {
                length: '20%',
                linearGradient: pointerLinearGradient,
            }
        }, {
            radius: '60%', value: 40,
            animation: { duration: 1000 },
            pointerWidth: 10,
            linearGradient: pointerLinearGradient,
            cap: {
                radius: 8, color: 'white',
                border: { color: '#E63B86', width: 1 }
            },
            needleTail: {
                length: '20%',
                linearGradient: pointerLinearGradient 
            }
        }];
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

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.

The radial gradient can be applied to all pointer types like marker, range bar and needle.

@using Syncfusion.EJ2.CircularGauge;
@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("container").Load("onGaugeLoad").Axes(axes => axes.Radius("90%").StartAngle(270).EndAngle(90)
                   .LineStyle(new CircularGaugeLine{ Width = 3, Color = "#E63B86" }).LabelStyle(new CircularGaugeLabel
                   {
                       Font = new CircularGaugeFont { Size = "0px" }
                   }).MajorTicks(new CircularGaugeTick
                   {
                       Height = 0,
                       Color = "transparent"
                   })
                   .MinorTicks(new CircularGaugeTick
                   {
                       Height = 0,
                       Color = "transparent"
                   }).Minimum(0).Maximum(100).Add()).Render()

<script>
    var pointerRadialGradient = {
        radius: '50%',
        innerPosition: { x: '50%', y: '50%' },
        outerPosition: { x: '50%', y: '50%' },
        colorStop: [
        { color: '#FEF3F9', offset: '0%', opacity: 0.9 },
        { color: '#E63B86', offset: '60%', opacity: 0.9 }]
    }
    function onGaugeLoad(sender) {
        sender.gauge.axes[0].pointers = [{
            radius: '80%',
            value: 80,
            animation: { enable: true, duration: 1000 },
            pointerWidth: 10,
            radialGradient: pointerRadialGradient,
            cap: {
                radius: 8,
                color: 'white',
                border: {
                    color: '#E63B86',
                    width: 1
                }
                },
            needleTail: {
                length: '20%',
                radialGradient: pointerRadialGradient
            }
        }, {
            radius: '60%', value: 40,
            animation: { duration: 1000 },
            pointerWidth: 10,
            radialGradient: pointerRadialGradient,
            cap: {
                radius: 8, color: 'white',
                border: { color: '#E63B86', width: 1 }
            },
            needleTail: {
                length: '20%',
                radialGradient: pointerRadialGradient
            }
        }];
    }
</script>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
    }
}

NOTE

View Sample in GitHub.