Search results

Axes in ASP.NET MVC Linear Gauge control

20 Apr 2021 / 3 minutes to read

Axes is a collection of linear axis which can be used to indicate the numeric values. Line, ticks, labels, ranges and pointers are the sub elements of an axis.

Line Customization

The line property of an axis provides options to customize the heightwidthcolor and offset of the axis line.

razor
line-customization.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(axis=>axis.Line(new
{
    height = 150,
    width = 2,
    color = "#4286f4",
    offset = 2
}).Add()).Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Ticks Customization

You can customize the height, color and width of major and minor ticks, by using majorTicks and minorTicks) property. By default, interval for major ticks will be calculated automatically and also you can customize the interval for major and minor ticks using interval property.

razor
ticks-customization.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(axis=>axis.Minimum(20).Maximum(140).MajorTicks(new
{
    interval = 20
}).MinorTicks(new
{
    interval = 5,
    color = "red"
}).Add()).Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Labels Customization

The labelStyle property of an axis provides options to customize the offsetformat, color and font of the axis labels.

razor
labels-customization.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(axis=>axis.LabelStyle(new
{
    format = "c"
}).Add()).Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Customize the display of the last label

If the last label is not in the visible range, it will be hidden by default. If you want to show the last label, set the ShowLastLabel property to true in the axes property of linear gauge.

razor
showlastlabel.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(axis=>axis.Line(new
{
    color = "#9E9E9E"
}).LabelStyle(new
{
    font (new {
	color='red'
	}
}).Add()).Render()
<script>
    window.gaugeLoad = function (args) {
        var axis = args.gauge.axes[0];
        axis.pointers = [{
            value: 20,
			height:15,
			width:15,
			offset:30,
			color:'#9E9E9E'

        }]
    }
</script>
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Label Format

Axis labels can be formatted by using the format property in labelStyle and it supports all the globalize formats.

razor
label-format.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(axis=>axis.Minimum(20).Maximum(140).LabelStyle(new
{
    format = "{value}°C"
}).Add()).Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

The following table describes the result of applying some commonly used label formats on numeric values.

Label Value Label Format property value Result Description
1000 n1 1000.0 The Number is rounded to 1 decimal place
1000 n2 1000.00 The Number is rounded to 2 decimal place
1000 n3 1000.000 The Number is rounded to 3 decimal place
0.01 p1 1.0% The Number is converted to percentage with 1 decimal place
0.01 p2 1.00% The Number is converted to percentage with 2 decimal place
0.01 p3 1.000% The Number is converted to percentage with 3 decimal place
1000 c1 $1,000.0 The Currency symbol is appended to number and number is rounded to 1 decimal place
1000 c2 $1,000.00 The Currency symbol is appended to number and number is rounded to 2 decimal place

Custom Label Format

Axis also supports custom label format using placeholder like {value}°C, in which the value represents the axis label e.g. 20°C.

razor
custom-label.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Width("100%").Height("50%").Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Orientation

By default, the Linear Gauge is rendered vertically. To change its orientation, the orientation property must be set to “Horizontal”

razor
orientation.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Orientation(Syncfusion.EJ2.LinearGauge.Orientation.Horizontal).Axes(new List<Syncfusion.EJ2.LinearGauge.LinearGaugeAxis> {
           new Syncfusion.EJ2.LinearGauge.LinearGaugeAxis
           {
               Minimum = 20, Maximum = 140,
           } }).Render();
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Inverted Axes

isInversed property is used to choose the rendering of axis either bottom to top or top to bottom direction.

razor
inverted-axes.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(axis=>axis.IsInversed(true).Add()).Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Opposed Axes

To place an axis opposite from its original position, set opposedPosition property as true in the axis.

razor
opposed-axes.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(axis=>axis.OpposedPosition(true).Add()).Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            return View();
        }
    }
}

Multiple Axes

You can render any number of axis for a linear gauge by using array of axis objects. Each axis will have its own ranges, pointers, annotations and customization options.

razor
multiple-axes.cs
Copied to clipboard
@using Syncfusion.EJ2;
@Html.EJS().LinearGauge("linear").Axes(ViewBag.axis).Render()
Copied to clipboard
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.Charts;
using Syncfusion.EJ2.LinearGauge;


namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            List<LinearGaugeAxis> axes = new List<LinearGaugeAxis>();
            LinearGaugeAxis axis1 = new LinearGaugeAxis();
            axis1.LabelStyle = new
            {
                format = "{value}°C"
            };
            axes.Add(axis1);
            ViewBag.axis = axes;
            LinearGaugeAxis axis2 = new LinearGaugeAxis();
            axis2.LabelStyle = new
            {
                format = "{value}°F"
            };
            axis2.OpposedPosition = true;
            axes.Add(axis2);
            ViewBag.axis = axes;
            return View();
        }
    }
}