|
| 1 | +--- |
| 2 | +title: Getting Started |
| 3 | +page_title: Getting Started |
| 4 | +description: "Make your first steps with the Telerik UI for {{ site.framework }} Circular Gauge component by following a complete step-by-step tutorial." |
| 5 | +slug: circulargauge_getting_started |
| 6 | +position: 1 |
| 7 | +--- |
| 8 | + |
| 9 | +# Getting Started with the Circular Gauge |
| 10 | + |
| 11 | +This tutorial explains how to set up a basic Telerik UI for {{ site.framework }} Circular Gauge and highlights the major steps in the configuration of the component. |
| 12 | + |
| 13 | +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. {% if site.core %}Finally, you can run the sample code in [Telerik REPL](https://netcorerepl.telerik.com/) and continue exploring the components.{% endif %} |
| 14 | + |
| 15 | +  |
| 16 | + |
| 17 | +@[template](/_contentTemplates/core/getting-started-prerequisites.md#repl-component-gs-prerequisites) |
| 18 | + |
| 19 | +## 1. Prepare the CSHTML File |
| 20 | +@[template](/_contentTemplates/core/getting-started-directives.md#gs-adding-directives) |
| 21 | + |
| 22 | +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. |
| 23 | + |
| 24 | +```html |
| 25 | + <style> |
| 26 | + #gauge-container { |
| 27 | + width: 386px; |
| 28 | + height: 386px; |
| 29 | + text-align: center; |
| 30 | + margin: 20px auto 30px auto; |
| 31 | + } |
| 32 | +
|
| 33 | + #gauge { |
| 34 | + width: 350px; |
| 35 | + height: 300px; |
| 36 | + margin: 0 auto; |
| 37 | + } |
| 38 | + </style> |
| 39 | + <div id="example"> |
| 40 | + |
| 41 | + <div id="gauge-container"> |
| 42 | + <p>Modify the Temperature with the Up and Down Arrows of the Keyboard</p> |
| 43 | + <!-- Component Configuration --> |
| 44 | + </div> |
| 45 | + </div> |
| 46 | +``` |
| 47 | + |
| 48 | +## 2. Initialize the Circular Gauge |
| 49 | + |
| 50 | +Use the Circular Gauge HtmlHelper {% if site.core %}or TagHelper{% endif %} to add the component to a page: |
| 51 | + |
| 52 | +* The `Name()` configuration method is mandatory as its value is used for the `id` and the `name` attributes of the Circular Gauge element. |
| 53 | +* Configure the text in the center of the gauge with the `CenterTemplate` property. |
| 54 | +* Set the color of the value pointer with the `Color` configuration method. |
| 55 | +* Utilize the `Value` method to set an initial value for the Circular Gauge. |
| 56 | + |
| 57 | +```HtmlHelper |
| 58 | + @using Kendo.Mvc.UI |
| 59 | +
|
| 60 | + @(Html.Kendo().CircularGauge() |
| 61 | + .Name("gauge") |
| 62 | + .Value(55) |
| 63 | + .Color("#1274AC") |
| 64 | + .CenterTemplate("Temperature") |
| 65 | + ) |
| 66 | +``` |
| 67 | +{% if site.core %} |
| 68 | +```TagHelper |
| 69 | + @using Kendo.Mvc.UI |
| 70 | + @addTagHelper *, Kendo.Mvc |
| 71 | +
|
| 72 | + <kendo-circulargauge name="gauge" value="55" center-template="Temperature" color="#1274AC"> |
| 73 | + </kendo-circulargauge> |
| 74 | +``` |
| 75 | +{% endif %} |
| 76 | + |
| 77 | +## 3. Configure the Circular Gauge |
| 78 | + |
| 79 | +Configure the [Scale](https://docs.telerik.com/{{ site.platform }}/api/kendo.mvc.ui.fluent/circulargaugebuilder#scalesystemaction) configuration method of the Circular Gauge. It exposes the [CircularGaugeSettingsBuilder](https://docs.telerik.com/{{ site.platform }}/api/kendo.mvc.ui.fluent/circulargaugescalesettingsbuilder) which allows you to then set up the `Min`, `Max`, `MajorTicks`, `MinorTicks`, `Labels` and `Reverse` properties. |
| 80 | + |
| 81 | +```HtmlHelper |
| 82 | + @using Kendo.Mvc.UI |
| 83 | +
|
| 84 | + @(Html.Kendo().CircularGauge() |
| 85 | + .Name("gauge") |
| 86 | + .Value(55) |
| 87 | + .Scale(x => |
| 88 | + x.Min(0) |
| 89 | + .Max(140) |
| 90 | + .MajorTicks(M=>M.Visible(true)) |
| 91 | + .MinorTicks(m => m.Visible(true)) |
| 92 | + .Labels(l => l.Visible(true)) |
| 93 | + ) |
| 94 | + .Color("#1274AC") |
| 95 | + .CenterTemplate("Temperature") |
| 96 | + ) |
| 97 | +``` |
| 98 | +{% if site.core %} |
| 99 | +```TagHelper |
| 100 | + @using Kendo.Mvc.UI |
| 101 | + @addTagHelper *, Kendo.Mvc |
| 102 | +
|
| 103 | + <kendo-circulargauge name="gauge" value="55" center-template="Temperature" color="#1274AC"> |
| 104 | + <scale min="0" max="140"> |
| 105 | + <major-ticks visible="true"/> |
| 106 | + <minor-ticks visible="true"/> |
| 107 | + <labels visible="true"/> |
| 108 | + </scale> |
| 109 | + </kendo-circulargauge> |
| 110 | +``` |
| 111 | +{% endif %} |
| 112 | + |
| 113 | + |
| 114 | +## 4. (Optional) Reference Existing Circular Gauge Instances |
| 115 | + |
| 116 | +You can reference the Circular Gauge instances that you have created and build on top of their existing configuration: |
| 117 | + |
| 118 | +1. Use the `id` attribute of the component instance to establish a reference. |
| 119 | + |
| 120 | + ```JavaScript |
| 121 | + $(document).ready( function (e) { |
| 122 | + var circulargaugeReference = $("#gauge").data("kendoCircularGauge"); // circulargaugeReference is a reference to the existing Circular Gauge instance of the helper. |
| 123 | + }); |
| 124 | + ``` |
| 125 | + |
| 126 | +1. Use the [Circular Gauge client-side API](https://docs.telerik.com/kendo-ui/api/javascript/ui/circulargauge#methods) to control the behavior of the component. In this example, you will use the [`value`](https://docs.telerik.com/kendo-ui/api/javascript/ui/circulargauge/methods/value) method to change the value of the Circular Gauge when the user presses the ArrowUp or ArrowDown keyboard buttons. |
| 127 | + |
| 128 | + ```JavaScript |
| 129 | + $("body").on("keydown",function(e){ |
| 130 | + if(e.key=="ArrowUp"){ |
| 131 | + updateValue(1); |
| 132 | + }else if(e.key=="ArrowDown"){ |
| 133 | + updateValue(-1); |
| 134 | + } |
| 135 | + }) |
| 136 | + |
| 137 | + function updateValue(number) { |
| 138 | + var gauge = $("#gauge").data("kendoCircularGauge"); |
| 139 | + gauge.value(gauge.value()+number); |
| 140 | + } |
| 141 | + ``` |
| 142 | + |
| 143 | +{% if site.core %} |
| 144 | +## Explore this Tutorial in REPL |
| 145 | + |
| 146 | +You can continue experimenting with the code sample above by running it in the Telerik REPL server playground: |
| 147 | + |
| 148 | +* [Sample code with the Circular Gauge HtmlHelper](https://netcorerepl.telerik.com/mHOsOmlJ43UV35SA53) |
| 149 | +* [Sample code with the Circular Gauge TagHelper](https://netcorerepl.telerik.com/GdkWOmbJ43QAvWvk39) |
| 150 | + |
| 151 | +{% endif %} |
| 152 | + |
| 153 | +## Next Steps |
| 154 | + |
| 155 | +* [Explore the Scale Options of the Circular Gauge]({% slug scale_circulargaugehelper_aspnetcore %}) |
| 156 | +* [Customize the Color of the Circular Gauge]({% slug colors_circulargaugehelper_aspnetcore %}) |
| 157 | + |
| 158 | +## See Also |
| 159 | + |
| 160 | +* [Using the API of the Circular Gauge for {{ site.framework }} (Demo)](https://demos.telerik.com/{{ site.platform }}/circulargauge/api) |
| 161 | +* [Client-Side API of the Circular Gauge](https://docs.telerik.com/kendo-ui/api/javascript/ui/circulargauge) |
| 162 | +* [Server-Side API of the Circular Gauge](/api/circulargauge) |
| 163 | +* [Knowledge Base Section](/knowledge-base) |
0 commit comments