Getting Started with ASP.NET Core Range Selector Control

23 Jul 20264 minutes to read

This section briefly explains how to include the ASP.NET Core Range Selector control in your ASP.NET Core application using Visual Studio.

Create an ASP.NET Core Web App with Razor Pages

Create an ASP.NET Core Web App using Visual Studio via Microsoft Templates or the Syncfusion® ASP.NET Core Extension. For detailed instructions, refer to the ASP.NET Core Web App Getting Started documentation.

Install the required ASP.NET Core package

To add ASP.NET Core Range Selector control in the app, open the NuGet package manager in Visual Studio (Tools → NuGet Package Manager → Manage NuGet Packages for Solution), search for and install the Syncfusion.AspNetCore.RangeNavigator package. All Syncfusion ASP.NET Core packages are available in nuget.org. See the NuGet packages topic for details.

Alternatively, you can install the same package using the Package Manager Console with the following command.

Install-Package Syncfusion.AspNetCore.RangeNavigator -Version 34.1.29

Add the ASP.NET Core Tag Helpers

After the package is installed, open the ~/Pages/_ViewImports.cshtml file and import the Syncfusion.AspNetCore.Base and Syncfusion.AspNetCore.Charts Tag Helpers.

@addTagHelper *, Syncfusion.AspNetCore.Base
@addTagHelper *, Syncfusion.AspNetCore.Charts

Add script resources

Include the script reference inside the <head> of ~/Pages/Shared/_Layout.cshtml.

<head>
    ...
    <!-- ASP.NET Core controls scripts -->
    <script src="_content/Syncfusion.AspNetCore.Charts/scripts/sf-range-navigator.min.js"></script>
</head>

Register the script manager

Open the ~/Pages/Shared/_Layout.cshtml file and register the script manager <ejs-scripts> at the end of the <body> element as follows.

<body>
    ...
    <!-- ASP.NET Core Script Manager -->
    <ejs-scripts></ejs-scripts>
</body>

Add ASP.NET Core Range Selector control

Add the ASP.NET Core Range Selector control in the ~/Pages/Index.cshtml file.

<ejs-rangenavigator></ejs-rangenavigator>

Populate Range Selector with data

Now, we are going to provide data to the Range Selector. Add a series object to the Range Selector by using series property. Now map the field names x and y in the JSON data to the xName and yNameproperties of the series, then set the JSON data to dataSource property. Since the JSON contains Datetime data, set the valueType as DateTime. By default, the axis valueType is Numeric.

@{
   
	List <data> dataSource = new List<data>
    {
        new data { x = new DateTime(2005, 01, 01), y = 21, y1 = 28 },
        new data { x = new DateTime(2006, 01, 01), y = 24, y1 = 44 },
        new data { x = new DateTime(2007, 01, 01), y = 36, y1 = 48 },
        new data { x = new DateTime(2008, 01, 01), y = 38, y1 = 50 },
        new data { x = new DateTime(2009, 01, 01), y = 54, y1 = 66 },
        new data { x = new DateTime(2010, 01, 01), y = 57, y1 = 78 },
        new data { x = new DateTime(2011, 01, 01), y = 70, y1 = 84 },
    };
}

<ejs-rangenavigator id="rangeNavigator" valueType="DateTime" labelFormat="MMM-yy">
    <e-rangenavigator-rangenavigatorseriescollection>
        <e-rangenavigator-rangenavigatorseries xName="x" yName="y" dataSource="dataSource"></e-rangenavigator-rangenavigatorseries>
    </e-rangenavigator-rangenavigatorseriescollection>
</ejs-rangenavigator>
public class data
{
    public DateTime x;
    public double y;
    public double y1;
}

Run the application

Press Ctrl+F5 (Windows) or +F5 (macOS) to launch the application. The ASP.NET Core Range Selector will render in your default web browser.

ASP.NET Core Range Selector Control

NOTE

View Sample in GitHub.

See also

  1. Getting Started with ASP.NET Core using Razor Pages
  2. Getting Started with ASP.NET Core MVC using Tag Helper