ComponentOne ASP.NET MVC Controls
LinearGauge Quick Start
ASP.NET MVC Controls > Controls > Gauge > Quick Start: Add and Configure > LinearGauge Quick Start

This section describes how to add a LinearGauge control to your MVC webform and set its value. For information on how to add a control, See Adding controls.

This topic comprises of three steps:

The following image shows how the LinearGauge appears after completing the steps above:

Step 1: Create an MVC Application

Create a new MVC application using the ComponentOne or VisualStudio templates. For more information about creating an MVC application, see Configuring your MVC Application topic.

Step 2: Add a new Controller and View

Add a new Controller:

  1. In the Solution Explorer, right click the folder Controllers.
  2. From the context menu, select Add | Controller. The Add Scaffold dialog appears.
  3. Complete the following steps in the Add Scaffold dialog:
    1. Select Empty MVC Controller template.
    2. Set name of the controller (for example: Default1Controller).
    3. Click Add.
  4. A new controller is added to the application.

Add a View for the controller:

  1. From the Solution Explorer, expand the folder Controllers and double click the controller (for example: Default1Controller) to open it.
  2. Place the cursor inside the method Index().
  3. Right click and select Add View. The Add View dialog appears.
  4. In the Add View dialog, verify that the View name is Index and View engine is Razor (CSHTML).
  5. Click Add. A view is added for the controller.

Step 3: Add the Control

  1. From the Solution Explorer, expand the folder Views.
  2. Double click Index.cshtml to open it.
  3. Replace the default code of the Index.cshtml file with the code given below to initialize a LinearGauge control and set the following properties:
    • Set the gauge Value to 35. The Value property denotes the gauge's current value.
    • Set the Min and Max properties to 0 and 100 respectively. The Min and Max properties specify the range of the gauge. You can add multiple ranges to a single gauge.
    • Set the Gauge's isReadOnly property to False. The isReadOnly specifies whether a user can edit the gauge's Value using a keyboard or a mouse.
    Razor
    Copy Code
    @(Html.C1().LinearGauge()
        .Width(500)
        .Height(100)
        .Value(35)
        .Thickness(0.1)
        .Min(0).Max(100)
    
        .Direction(C1.Web.Mvc.GaugeDirection.Right)
            // Create and Customize Ranges
             .Ranges(items => items
                .Add(item => item.Min(0).Max(40).Color(System.Drawing.Color.Red))
                .Add(item => item.Min(40).Max(80).Color(System.Drawing.Color.Yellow))
                .Add(item => item.Min(80).Max(100).Color(System.Drawing.Color.Green))
            )
    )
    
    HTML
    Copy Code
    <c1-linear-gauge width="500px" height="100px" value="35"
                     thickness="0.1" min="0" max="100" direction="C1.Web.Mvc.GaugeDirection.Right">
        <c1-gauge-range min="0" max="40" color="red"></c1-gauge-range>
        <c1-gauge-range min="40" max=80 color="yellow"></c1-gauge-range>
        <c1-gauge-range min="80" max="100" color="green"></c1-gauge-range>
    </c1-linear-gauge>
    

Step 4: Build and Run the Project

  1. Click Build | Build Solution to build the project.
  2. Press F5 to run the project.
    Append the folder name and view name to the generated URL (for example: http://localhost:1234/Default1/index) in the address bar of the browser to see the view. Or link the view to the home page.

Back to Top

See Also