Ranges in Circular Gauge Control

19 Dec 202213 minutes to read

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.

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular2").Axes(axes =>
    axes.Ranges(range =>range.Start(20).End(80).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

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

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular2").Axes(axes =>
    axes.Ranges(range =>range.Start(20).End(80).StartWidth(15).EndWidth(15).Color("#ff5985").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();
        }
    }
}

Radius

You can place the range inside or outside of the axis by using radius property. The radius of the range can take 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.

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular2").Axes(axes =>
    axes.Ranges(range =>range.Start(20).End(80).Radius("100").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();
        }
    }
}

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.

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular2").Axes(axes =>
    axes.Ranges(range =>range.Start(20).End(80).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();
        }
    }
}

Dragging Ranges

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.

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular").Height("250px").Width("250px").EnableRangeDrag(true).Axes(axes => axes
.Pointers(pointer => pointer.Value(50)).Ranges(range =>range.Start(0).End(100).StartWidth(8).EndWidth(8).Radius("108%").Color("#30B32D").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 Ranges

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

NOTE

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

@using Syncfusion.EJ2;

@Html.EJS().CircularGauge("circular2").Axes(axes =>
    axes.Minimum(0).Maximum(100).MajorTicks(mt =>mt.UseRangeColor(true)).
    MinorTicks(minor=> minor.UseRangeColor(true))
    .LabelStyle(labels =>labels.UseRangeColor(true))
    .Ranges(range => {
        range.Start(0).End(25).Radius("108%").Add();
        range.Start(25).End(50).Radius("70%").Add();
        range.Start(50).End(75).Radius("70%").Add();
        range.Start(75).End(100).Radius("108%").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();
        }
    }
}

Rounded corner radius

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

@using Syncfusion.EJ2;


@Html.EJS().CircularGauge("circular2").Axes(axes =>
    axes.Ranges(range => range.Start(20).End(80).Radius("60%").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();
        }
    }
}

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.

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

@Html.EJS().CircularGauge("container").Load("onGaugeLoad").Axes(axes => axes
         .Radius("80%").StartAngle(200).EndAngle(160).Minimum(0).Maximum(100).LabelStyle(ls => ls.Position(Position.Inside))
         .MajorTicks(major => major.Height(0)).MinorTicks(minor => minor.Height(0))
         .Pointers(pt => pt.Value(60).RoundedCornerRadius(20).PointerWidth(0).Cap(cap => cap.Radius(0)).Add())
         .LineStyle(lin => lin.Width(0))
         .Add()).Render()

<script>
    var rangeLinearGradient = {
        startValue: '0%',
        endValue: '100%',
        colorStop: [
            { color: '#9E40DC', offset: '0%', opacity: 0.9 },
            { color: '#E63B86', offset: '70%', opacity: 0.9 }
        ]
    }
    function onGaugeLoad(sender) {
        sender.gauge.axes[0].minorTicks.height = 0;
        sender.gauge.axes[0].majorTicks.height = 0;
        sender.gauge.axes[0].labelStyle.font.size = "0px";
        sender.gauge.axes[0].ranges = [{
            start: 0,
            end: 100,
            radius: '90%',
            startWidth: 30,
            endWidth: 30,
            color: '#E0E0E0',
            roundedCornerRadius: 20,
            linearGradient: rangeLinearGradient
        }];
    }
</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.

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

@Html.EJS().CircularGauge("container").Load("onGaugeLoad").Axes(axes => axes
         .Radius("80%").StartAngle(200).EndAngle(160).Minimum(0).Maximum(100).LabelStyle(ls => ls.Position(Position.Inside))
         .MajorTicks(major => major.Height(0)).MinorTicks(minor => minor.Height(0))
         .Pointers(pt => pt.Value(60).RoundedCornerRadius(20).PointerWidth(0).Cap(cap => cap.Radius(0)).Add())
         .LineStyle(lin => lin.Width(0))
         .Add()).Render()

<script>
    var rangeRadialGradient = {
        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 }]
    }
    function onGaugeLoad(sender) {
        sender.gauge.axes[0].minorTicks.height = 0;
        sender.gauge.axes[0].majorTicks.height = 0;
        sender.gauge.axes[0].labelStyle.font.size = "0px";
        sender.gauge.axes[0].ranges = [{
            start: 0,
            end: 100,
            radius: '90%',
            startWidth: 30,
            endWidth: 30,
            color: '#E0E0E0',
            roundedCornerRadius: 20,
            radialGradient: rangeRadialGradient
        }];
    }
</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.

See also