Search results

Annotations

Annotations are used to mark a specific area of interest in the gauge with texts, shapes or images.

Content

You can place any custom element on the axis area by assigning the id of the element to content property of annotation object.

razor
annotations.cs
@using Syncfusion.EJ2;
@Html.EJS().CircularGauge("circular").Load("gaugeload").Render()
<script>
    window.gaugeload = function (args) {
        var axis = args.gauge.axes[0];
        axis.annotations = [{
            content: '#annotation-template'
        }],
        axis.pointers = [{
             value: 50
        }]
    }
</script>
<script id='annotation-template' type="text/x-template">
    <div id='templateWrap'>
        <div class='des'>
            <span>Pointer Value : 50</span>
        </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();
        }
    }
}

Position

Annotation can be placed around the axis by using radius and angle property. For example, if the angle is 90 degree and the radius is 110%, then the annotation, will be placed at the right side of the axis.

Radius of the annotation takes value either in pixel or percentage. By setting value in percentage, annotation gets its position with respect to its axis radius.

razor
position.cs
@using Syncfusion.EJ2;
@Html.EJS().CircularGauge("circular").Load("gaugeload").Render()
<script>
    window.gaugeload = function (args) {
        var axis = args.gauge.axes[0];
        axis.annotations = [{
            content: '#annotation-template',
            angle: 90,
            radius: '150%'
        }],
        axis.pointers = [{
             value: 50
        }]
    }
</script>
<script id='annotation-template' type="text/x-template">
    <div id='templateWrap'>
        <div class='des'>
            <span>Pointer Value : 50</span>
        </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();
        }
    }
}

Sub Gauge

As the annotation allows you to place any custom element, we can initialize a gauge to the element and can be used to place that in another gauge.

razor
subgauge.cs
@using Syncfusion.EJ2;
@Html.EJS().CircularGauge("circular").Axes(axis=> axis.Minimum(0).Maximum(12).LabelStyle(new
{
    hiddenLabel = "First"

}).LineStyle(new
{
    width = "0"
}).StartAngle(0).EndAngle(360).Annotations(ViewBag.annotations).Pointers(ViewBag.pointers).Ranges(ViewBag.ranges).Add()).Render()

@Html.EJS().CircularGauge("subGauge").Axes(subaxis=>subaxis.Minimum(0).Maximum(12).LabelStyle(new
{
    hiddenLabel = "First",
    offset = -5

}).MajorTicks(new
{
    interval = 3

}).LineStyle(new {
    width= "0"
}).StartAngle(0).EndAngle(360).Pointers(ViewBag.subgauge_pointers).Ranges(ViewBag.subgauge_ranges).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;
using Syncfusion.EJ2.CircularGauge;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            List<CircularGaugeRange> ranges = new List<CircularGaugeRange>();
            CircularGaugeRange range1 = new CircularGaugeRange();
            range1.Start = 0;
            range1.End = 3;
            range1.Color = "rgba(29,29,29,0.7)";
            ranges.Add(range1);
            CircularGaugeRange range2 = new CircularGaugeRange();
            range2.Start = 3;
            range2.End = 12;
            range2.Color = "rgba(168,145,102,0.1)";
            ranges.Add(range2);
            ViewBag.ranges = ranges;
            List<CircularGaugeAnnotation> annotations = new List<CircularGaugeAnnotation>();
            CircularGaugeAnnotation annotation1 = new CircularGaugeAnnotation();
            annotation1.Angle = 270;
            annotation1.Radius = "40%";
            annotation1.Content = "<div id=subGauge2 style=width: 90px; height: 90px;></div>";
            annotations.Add(annotation1);
            CircularGaugeAnnotation annotation2 = new CircularGaugeAnnotation();
            annotation2.Angle = 90;
            annotation2.Radius = "40%";
            annotation2.Content = "<div id=time><span>6:30 PM</span></div>";
            annotations.Add(annotation2);
            ViewBag.annotations = annotations;
            List<CircularGaugePointer> pointers = new List<CircularGaugePointer>();
            CircularGaugePointer pointer1 = new CircularGaugePointer();
            pointer1.PointerWidth = 5;
            pointer1.Radius = "40%";
            pointer1.Value = 6.5;
            pointer1.Border = new
            {
                width = 1,
                color = "rgb(29,29,29)"
            };
            pointer1.Cap = new
            {
                color = "rgb(29,29,29)",
                radius = 0,
                border = new
                {
                    width = 0.2,
                    color = "red"
                }
            };
            pointer1.NeedleTail = new
            {
                length = "0%"
            };
            pointer1.Animation = new { enable = false };
            pointers.Add(pointer1);
            CircularGaugePointer pointer2 = new CircularGaugePointer();
            pointer2.PointerWidth = 5;
            pointer2.Radius = "60%";
            pointer2.Color = "rgb(29,29,29)";
            pointer2.Value = 6;
            pointer2.Border = new
            {
                width = 1,
                color = "rgb(29,29,29)"
            };
            pointer2.Cap = new
            {
                color = "rgb(29,29,29)",
                radius = 0,
                border = new
                {
                    width = 0.2,
                    color = "red"
                }
            };
            pointer2.NeedleTail = new
            {
                length = "0%"
            };
            pointer2.Animation = new { enable = false };
            pointers.Add(pointer2);
            CircularGaugePointer pointer3 = new CircularGaugePointer();
            pointer3.PointerWidth = 4;
            pointer3.Radius = "70%";
            pointer3.Color = "rgba(168,145,102,1)";
            pointer3.Value = 9.8;
            pointer3.Cap = new
            {
                color = "rgba(168,145,102,1)",
                radius = 4,
                border = new
                {
                    width = 0.2,
                    color = "rgba(168,145,102,1)"
                }
            };
            pointer3.NeedleTail = new
            {
                color = "rgba(168,145,102,1)",
                length = "20%"
            };
            pointer3.Animation = new { enable = false, duration=0 };
            pointers.Add(pointer3);
            ViewBag.pointers = pointers;
            List<CircularGaugeRange> subgaugeranges = new List<CircularGaugeRange>();
            CircularGaugeRange ranges4 = new CircularGaugeRange();
            ranges4.Start = 0;
            ranges4.End = 3;
            ranges4.StartWidth = "5";
            ranges4.EndWidth = "5";
            ranges4.Color = "rgba(29,29,29,0.7)";
            subgaugeranges.Add(ranges4);
            CircularGaugeRange ranges5 = new CircularGaugeRange();
            ranges5.Start = 3;
            ranges5.End = 12;
            ranges5.StartWidth = "5";
            ranges5.EndWidth = "5";
            ranges5.Color = "rgba(168,145,102,0.1)";
            subgaugeranges.Add(ranges5);
            ViewBag.subgauge_ranges = subgaugeranges;
            List<CircularGaugePointer> subpointers = new List<CircularGaugePointer>();
            CircularGaugePointer pointer4 = new CircularGaugePointer();
            pointer4.PointerWidth = 2;
            pointer4.Radius = "40%";
            pointer4.Animation = new { enable = false};
            pointer4.Color = "rgb(29,29,29)";
            pointer4.Border = new
            {
                width = 1,
                color = "rgb(29,29,29)"
            };
            pointer4.Cap = new
            {
                color = "rgb(29,29,29)",
                radius = 2,
                border = new
                {
                    width= 0.2,
                    color= "red"
                }
            };
            pointer4.NeedleTail = new
            {
                length = "0%"
            };
            subpointers.Add(pointer4);
            ViewBag.subgauge_pointers = subpointers;
            return View();
        }
    }
}