New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Getting Started with the ArcGauge

This tutorial explains how to set up a basic Telerik UI for ASP.NET MVC ArcGauge and highlights the major steps in the configuration of the component.

You will initialize an ArcGauge component with different colors depending on the current value. Next, you will use the built-in client-side methods to update the ArcGauge options and change its value dynamically.

Sample Telerik UI for ASP.NET MVC ArcGauge

Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET MVC components:

1. Prepare the CSHTML File

The first step is to add the required directives at the top of the .cshtml document:

  • To use the Telerik UI for ASP.NET MVC HtmlHelpers:

    @using Kendo.Mvc.UI
    

Optionally, you can structure the View content by adding the desired HTML elements like headings, divs, paragraphs, and others.

    @using Kendo.Mvc.UI

    <div id="gauge-container">

    </div>

2. Initialize the ArcGauge

Use the ArcGauge HtmlHelper to add the component to a page:

  • The Name() configuration method is mandatory as its value is used for the id and the name attributes of the ArcGauge element.
  • The Scale() option specifies the ArcGauge scale options, like labels, the lowest and highest value, and more.
  • The Value() option sets the initial ArcGauge value.
  • The CenterTemplate() specifies the label template displayed in the center of the arc.
    @using Kendo.Mvc.UI

    <div id="gauge-container">
        @(Html.Kendo().ArcGauge()
            .Name("gauge")
            .Value(50)
            .Scale(x => x.Min(0).Max(100))
            .CenterTemplate("<span>#: value #%</span>")
        )
    </div>

3. Configure the Color Ranges

The next step is to set up the color ranges of the ArcGauge and update the label template to display the current value in the respective color.

    @using Kendo.Mvc.UI

    <div id="gauge-container">
        @(Html.Kendo().ArcGauge()
            .Name("gauge")
            .Value(50)
            .Scale(x => x.Min(0).Max(100))
            .CenterTemplate("<span style='color: #: color #;'>#: value #%</span>")
            .Colors(colors =>
            {
                colors.Add().From(0).To(25).Color("#0058e9");
                colors.Add().From(25).To(50).Color("#37b400");
                colors.Add().From(50).To(75).Color("#ffc000");
                colors.Add().From(75).To(100).Color("#f31700");
            })
        )
    </div>

4. (Optional) Reference Existing ArcGauge Instances

You can reference the ArcGauge instances that you have created and build on top of their existing configuration:

  1. Use the id attribute of the component instance to get its reference.

        <script>
            $(document).ready(function() {
                var arcGaugeReference = $("#gauge").data("kendoArcGauge"); // arcGaugeReference is a reference to the existing ArcGauge instance of the helper.
            });
        </script>
    
  2. Use the ArcGauge client-side API to control the behavior of the component. In this example, you will use the value() method to change the ArcGauge value and the setOptions() method to update the background color (for example, when a button is clicked).

        @(Html.Kendo().Button()
            .Name("btn")
            .Content("Update value")
            .Events(ev => ev.Click("onBtnClick"))
        )
    
        <script>
            function onBtnClick() {
                var arcGaugeReference = $("#gauge").data("kendoArcGauge");
                if(arcGaugeReference.value() < 80) {
                    arcGaugeReference.setOptions({gaugeArea: {background: "#FFD700"}});
                    arcGaugeReference.value(80);
                }
            }
        </script>
    

For more information on referencing specific helper instances, see the Methods and Events article.

Next Steps

See Also

In this article