Annotations in Circular Gauge Control

19 Dec 202224 minutes to read

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.

@using Syncfusion.EJ2;

<div id="container">
    <ejs-circulargauge id="circular">
        <e-circulargauge-axes>
            <e-circulargauge-axis>
                <e-circulargauge-annotations>
                    <e-circulargauge-annotation content="#annotation-template" zIndex="1"></e-circulargauge-annotation>
                </e-circulargauge-annotations>
                <e-circulargauge-pointers>
                    <e-circulargauge-pointer value="50"></e-circulargauge-pointer>
                </e-circulargauge-pointers>
            </e-circulargauge-axis>
        </e-circulargauge-axes>
    </ejs-circulargauge>
</div>
<script id='annotation-template' type="text/x-template">
    <div id='templateWrap'>
        <div class='des'>
            <span>Pointer Value : 50</span>
        </div>
    </div>
</script>

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.

@using Syncfusion.EJ2;

<div id="container">
    <ejs-circulargauge id="circular">
        <e-circulargauge-axes>
            <e-circulargauge-axis>
                <e-circulargauge-annotations>
                    <e-circulargauge-annotation content="#annotation-template" angle="90" radius="150%" zIndex="1"></e-circulargauge-annotation>
                </e-circulargauge-annotations>
                <e-circulargauge-pointers>
                    <e-circulargauge-pointer value="50"></e-circulargauge-pointer>
                </e-circulargauge-pointers>
            </e-circulargauge-axis>
        </e-circulargauge-axes>
    </ejs-circulargauge>
</div>
<script id='annotation-template' type="text/x-template">
    <div id='templateWrap'>
        <div class='des'>
            <span>Pointer Value : 50</span>
        </div>
    </div>
</script>

Sub Gauge

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

@using Syncfusion.EJ2;

<ejs-circulargauge id="circular">
    <e-circulargauge-axes>
        <e-circulargauge-axis minimum="0" maximum="12" startAngle="0" endAngle="360">
            <e-axis-labelstyle hiddenLabel="First"></e-axis-labelstyle>
            <e-axis-linestyle width="0"></e-axis-linestyle>
            <e-circulargauge-ranges>
                <e-circulargauge-range start="0" end="3" color="rgba(29,29,29,0.7)"></e-circulargauge-range>
                <e-circulargauge-range start="3" end="12" color="rgba(168,145,102,0.1)"></e-circulargauge-range>
            </e-circulargauge-ranges>
            <e-circulargauge-annotations>
                <e-circulargauge-annotation content="<div id='subGauge' style='width:90px;height:90px;'></div>" angle="270" radius="40%" zIndex="1"></e-circulargauge-annotation>
                <e-circulargauge-annotation content="<div id='time'><span>6:30 PM</span></div>" angle="90" radius="40%" zIndex="1"></e-circulargauge-annotation>
            </e-circulargauge-annotations>
            <e-circulargauge-pointers>
                <e-circulargauge-pointer value="6.5" radius="40%" color="rgb(29,29,29)" pointerWidth="5">
                    <e-pointer-cap radius="0" color="rgb(29,29,29)">
                        <e-pointers-cap-border color="red" width="0.2"></e-pointers-cap-border>
                    </e-pointer-cap>
                    <e-pointer-border color="rgb(29,29,29)" width="1"></e-pointer-border>
                    <e-pointer-needletail length="0%"></e-pointer-needletail>
                    <e-pointer-animation enable="false"></e-pointer-animation>
                </e-circulargauge-pointer>
                <e-circulargauge-pointer value="6" radius="60%" color="rgb(29,29,29)" pointerWidth="5">
                    <e-pointer-cap radius="0" color="rgb(29,29,29)">
                        <e-pointers-cap-border color="red" width="0.2"></e-pointers-cap-border>
                    </e-pointer-cap>
                    <e-pointer-border color="rgb(29,29,29)" width="1"></e-pointer-border>
                    <e-pointer-needletail length="0%"></e-pointer-needletail>
                    <e-pointer-animation enable="false"></e-pointer-animation>
                </e-circulargauge-pointer>
                <e-circulargauge-pointer value="9.8" radius="70%" color="rgba(168,145,102,1)" pointerWidth="4">
                    <e-pointer-cap radius="4" color="rgba(168,145,102,1)">
                        <e-pointers-cap-border color="rgba(168,145,102,1)" width="0.2"></e-pointers-cap-border>
                    </e-pointer-cap>
                    <e-pointer-needletail length="20%" color="rgba(168,145,102,1)"></e-pointer-needletail>
                    <e-pointer-animation enable="false"></e-pointer-animation>
                </e-circulargauge-pointer>
            </e-circulargauge-pointers>
        </e-circulargauge-axis>
    </e-circulargauge-axes>
</ejs-circulargauge>
<ejs-circulargauge id="subGauge">
    <e-circulargauge-axes>
        <e-circulargauge-axis minimum="0" maximum="12" startAngle="0" endAngle="360">
            <e-axis-labelstyle hiddenLabel="First"></e-axis-labelstyle>
            <e-axis-majorticks interval="3"></e-axis-majorticks>
            <e-circulargauge-ranges>
                <e-circulargauge-range start="0" end="3" color="rgba(29,29,29,0.7)" startWidth="5" endWidth="5"></e-circulargauge-range>
                <e-circulargauge-range start="3" end="12" color="rgba(168,145,102,0.1)" startWidth="5" endWidth="5"></e-circulargauge-range>
            </e-circulargauge-ranges>
            <e-axis-linestyle width="0"></e-axis-linestyle>
            <e-circulargauge-pointers>
                <e-circulargauge-pointer radius="40%" color="rgb(29,29,29)" pointerWidth="2">
                    <e-pointer-cap radius="2" color="rgb(29,29,29)">
                        <e-pointers-cap-border color="red" width="0.2"></e-pointers-cap-border>
                    </e-pointer-cap>
                    <e-pointer-border color="rgb(29,29,29)" width="1"></e-pointer-border>
                    <e-pointer-needletail length="0%"></e-pointer-needletail>
                    <e-pointer-animation enable="false"></e-pointer-animation>
                </e-circulargauge-pointer>
            </e-circulargauge-pointers>
        </e-circulargauge-axis>
    </e-circulargauge-axes>
</ejs-circulargauge>
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 CircularGaugeBorder
            {
                Width = 1,
                Color = "rgb(29,29,29)"
            };
            pointer1.Cap = new CircularGaugeCap
            {
                Color = "rgb(29,29,29)",
                Radius = 0,
                Border = new CircularGaugeBorder
                {
                    Width = 0.2,
                    Color = "red"
                }
            };
            pointer1.NeedleTail = new CircularGaugeNeedleTail
            {
                Length = "0%"
            };
            pointer1.Animation = new CircularGaugeAnimation { 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 CircularGaugeBorder
            {
                Width = 1,
                Color = "rgb(29,29,29)"
            };
            pointer2.Cap = new CircularGaugeCap
            {
                Color = "rgb(29,29,29)",
                Radius = 0,
                Border = new CircularGaugeBorder
                {
                    Width = 0.2,
                    Color = "red"
                }
            };
            pointer2.NeedleTail = new CircularGaugeNeedleTail
            {
                Length = "0%"
            };
            pointer2.Animation = new CircularGaugeAnimation{ 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 CircularGaugeCap
            {
                Color = "rgba(168,145,102,1)",
                Radius = 4,
                Border = new CircularGaugeBorder
                {
                    Width = 0.2,
                    Color = "rgba(168,145,102,1)"
                }
            };
            pointer3.NeedleTail = new CircularGaugeNeedleTail
            {
                Color = "rgba(168,145,102,1)",
                Length = "20%"
            };
            pointer3.Animation = new CircularGaugeAnimation { 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 CircularGaugeAnimation { Enable = false };
            pointer4.Color = "rgb(29,29,29)";
            pointer4.Border = new CircularGaugeBorder
            {
                Width = 1,
                Color = "rgb(29,29,29)"
            };
            pointer4.Cap = new CircularGaugeCap
            {
                Color = "rgb(29,29,29)",
                Radius = 2,
                Border = new CircularGaugeBorder
                {
                    Width = 0.2,
                    Color = "red"
                }
            };
            pointer4.NeedleTail = new CircularGaugeNeedleTail
            {
                Length = "0%"
            };
            subpointers.Add(pointer4);
            ViewBag.subgauge_pointers = subpointers;
            return View();
        }
    }
}

NOTE

View Sample in GitHub.

See also