# Getting Started with the Circular Gauge

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

You will initialize a Circular Gauge and configure its `Scale`, which is responsible for the visualization of the gauge. Then, you will handle the basic JavaScript `keydown` event to acknowledge when the user presses the `Up` or `Down` arrow keys and update the value of the Circular Gauge using its client-side reference.

![Sample Telerik UI for ASP.NET MVC  Circular Gauge](https://www.telerik.com/aspnet-mvc/documentation/assets/1d9867ad9260186c6a25ad442e04ebfb/circulargauge-getting-started.png)

## Prerequisites

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

* To create a new pre-configured project for the Telerik UI for ASP.NET MVC components, you can [use a project template](https://www.telerik.com/aspnet-mvc/documentation/getting-started-mvc/first-steps).

* To manually configure an existing project by using NuGet, see the [Adding Telerik UI through NuGet](https://www.telerik.com/aspnet-mvc/documentation/getting-started/setup-with-nuget).

## 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:

  ```cshtml
  @using Kendo.Mvc.UI
  ```

Optionally, you can structure the document by adding the desired HTML elements like headings, divs, and paragraphs. In this tutorial, you will also apply some styles to the gauge and its container.

```html
    <style>
        #gauge-container {
            width: 386px;
            height: 386px;
            text-align: center;
            margin: 20px auto 30px auto;
        }

        #gauge {
            width: 350px;
            height: 300px;
            margin: 0 auto;
        }
    </style>
    <div id="example">
        
        <div id="gauge-container">
            <p>Modify the Temperature with the Up and Down Arrows of the Keyboard</p>
            
        </div>
    </div>
```

## 2. Initialize the Circular Gauge

Use the Circular Gauge 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 Circular Gauge element.
* Configure the text in the center of the gauge with the `CenterTemplate` property.
* Set the color of the value pointer with the `Color` configuration method.
* Utilize the `Value` method to set an initial value for the Circular Gauge.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    @(Html.Kendo().CircularGauge()
        .Name("gauge")
        .Value(55)
        .Color("#1274AC")
        .CenterTemplate("Temperature")
    )
```

## 3. Configure the Circular Gauge

Configure the [Scale](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/circulargaugebuilder#scalesystemaction) configuration method of the Circular Gauge. It exposes the [CircularGaugeSettingsBuilder](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/circulargaugescalesettingsbuilder) which allows you to then set up the `Min`, `Max`, `MajorTicks`, `MinorTicks`, `Labels` and `Reverse` properties.

```Razor HtmlHelper
    @using Kendo.Mvc.UI

    @(Html.Kendo().CircularGauge()
        .Name("gauge")
        .Value(55)
        .Scale(x =>
           x.Min(0)
            .Max(140)
            .MajorTicks(M=>M.Visible(true))
            .MinorTicks(m => m.Visible(true))
            .Labels(l => l.Visible(true))
        )
        .Color("#1274AC")
        .CenterTemplate("Temperature")
    )
```

## 4. (Optional) Reference Existing Circular Gauge Instances

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

1. Use the `id` attribute of the component instance to establish a reference.

   ```JavaScript
       $(document).ready( function (e) {
           var circulargaugeReference = $("#gauge").data("kendoCircularGauge"); // circulargaugeReference is a reference to the existing Circular Gauge instance of the helper.
       });
   ```

2. Use the [Circular Gauge client-side API](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/circulargauge#methods) to control the behavior of the component. In this example, you will use the [`value()`](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/circulargauge/methods/value) method to change the value of the Circular Gauge when the user presses the `ArrowUp` or `ArrowDown` keyboard buttons.

   ```JavaScript
       $("body").on("keydown",function(e){
           if(e.key=="ArrowUp"){
               updateValue(1);
           }else if(e.key=="ArrowDown"){
               updateValue(-1);
           }
       })   
       
       function updateValue(number) {
           var gauge = $("#gauge").data("kendoCircularGauge");
           gauge.value(gauge.value()+number);
       }
   ```

## Next Steps

* [Explore the Scale Options of the Circular Gauge](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/gauges/circulargauge/scale)
* [Customize the Color of the Circular Gauge](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/gauges/circulargauge/colors)

## See Also

* [Using the API of the Circular Gauge for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/circular-gauge/api)
* [Client-Side API of the Circular Gauge](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/circulargauge)
* [Server-Side API of the Circular Gauge](https://www.telerik.com/aspnet-mvc/documentation/api/circulargauge)
* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
