# Getting Started with the Linear Gauge

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

You will initialize a Linear Gauge and set up the `Scale` property, which configures the visualization of the gauge. Then, you will use JavaScript to update the value of the Linear Gauge using its client-side reference.

![Sample Telerik UI for ASP.NET MVC Linear Gauge](https://www.telerik.com/aspnet-mvc/documentation/assets/c67a19956acf8b6919351e13eb196ac3/getting-started-lineargauge.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
    <h2>Tempretature scale of the Pasteurization Process</h2>
    <div class="legend">
        <div class="legend-item">
            <span class="color red"></span>
                Temperature is too high.
        </div>
        <div class="legend-item">
            <span class="color yellow"></span>
                Temperature is right for pasteurization.
        </div>
        <div class="legend-item">
            <span class="color blue"></span>
                Temperature is too low.
        </div>
    </div>
    <div id="gauge-container">
            
    </div>
    <style>
        #gauge-container {
            text-align: center;
            margin: 0 auto;
            background: transparent url("@Url.Content("~/shared/dataviz/gauge/linear-gauge-container.png")") no-repeat 50% 50%;
            background-size: contain;
            background-position:bottom;
            padding: 18px;
            width: 320px;
            height: 320px;
        }

        #gauge {
            height: 100%;
            display: inline-block;
            zoom: 1;
        }
        h2{
            display:flex;
            justify-content:center;
        }
        .legend-item{
            display:flex;
            flex-direction: row;
        }
        .color{
            display:flex;
            width: 15px;
            height: 15px;
            margin-right:5px;
            border-radius:30%;
        }
        .red{
            background-color:#c20000;
        }
        .yellow{
            background-color:#ffc700;
        }
        .blue{
            background-color:#2798df;
        }
    </style>
```

## 2. Initialize the Linear Gauge

Use the Linear 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 Linear Gauge element.
* Utilize the [`LinearGaugePointerBuilder`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugepointerbuilder)'s [`Value`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugepointerbuilder#valuesystemdouble) method to set an initial value for the Linear Gauge.

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

   @(Html.Kendo().LinearGauge()
          .Name("gauge")
          .Pointer(pointer => pointer.Value(56))
    )
```

## 3. Configure the Linear Gauge

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

The [`Ranges`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugescalesettingsrangebuilder) property exposes the following configuration methods that are responsible for the graphics rendering of the component:

* [`From`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugescalesettingsrangebuilder#fromsystemdouble) — The start position of the range in scale units.
* [`To`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugescalesettingsrangebuilder#tosystemdouble) — The end position of the range in scale units.
* [`Color`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugescalesettingsrangebuilder#colorsystemstring) — The color of the range. Any valid CSS color string will work here, including hex and rgb.
* [`Opacity`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugescalesettingsrangebuilder#opacitysystemdouble) — The opacity of the range.

Finally, fine tune the size and the position of the component with the [`GaugeAreas`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/lineargaugegaugeareasettingsbuilder)'s `Height` and `Margin` properties.

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

   @(Html.Kendo().LinearGauge()
          .Name("gauge")
          .Pointer(pointer => pointer.Value(56))
          .Scale(scale => scale
              .MajorUnit(20)
              .MinorUnit(2)
              .Min(0)
              .Max(130)
              .Ranges(ranges =>
              {
                  ranges.Add().From(0).To(70).Color("#2798df");
                  ranges.Add().From(70).To(100).Color("#ffc700");
                  ranges.Add().From(100).To(130).Color("#c20000");
              }
              )
          )
          .GaugeArea(g=>g.Height(280).Margin(m=>m.Top(30)))
    )
```

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

You can reference the Linear 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 lineargaugeReference = $("#gauge").data("kendoLinearGauge"); // lineargaugeReference is a reference to the existing Linear Gauge instance of the helper.
       });
   ```

2. Use the [Linear Gauge client-side API](https://www.telerik.com/kendo-jquery-ui/documentation/api/dataviz/ui/lineargauge#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/lineargauge/methods/value) method to change the value of the Linear Gauge every second.

   ```JavaScript
       setInterval(function(){
           updateValue(temperatureSensor); // update the value of the Linear Gauge based on external input every second
       },1000)
       
       function updateValue(number) {
           var gauge = $("#gauge").data("kendoLinearGauge");
           gauge.value(number);
       }
   ```

## Next Steps

* [Explore the Scale Options of the Linear Gauge](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/gauges/lineargauge/scale)
* [Customize the Pointers of the Linear Gauge](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/gauges/lineargauge/pointers)

## See Also

* [Client-Side API of the Linear Gauge](https://docs.telerik.com/kendo-ui/api/dataviz/ui/lineargauge)
* [Server-Side API of the Linear Gauge](https://www.telerik.com/aspnet-mvc/documentation/api/lineargauge)
* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
