How can I help you?
Getting started with EJ2 TypeScript Range Navigator control
19 Feb 202610 minutes to read
This document explains how to create a simple Range Navigator and configure its features in TypeScript using the Essential JS 2 webpack quickstart seed repository.
This application is integrated with the
webpack.config.jsconfiguration and uses the latest version of the webpack-cli. It requires nodev14.15.0or higher. For more information about webpack and its features, refer to the webpack getting-started guide.
Dependencies
The list of minimum dependencies required to use a Range Navigator is as follows:
|-- @syncfusion/ej2-charts
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-data
|-- @syncfusion/ej2-pdf-export
|-- @syncfusion/ej2-file-utils
|-- @syncfusion/ej2-compression
|-- @syncfusion/ej2-navigations
|-- @syncfusion/ej2-calendars
Set up development environment
Open the command prompt from the required directory, and run the following command to clone the Syncfusion JavaScript (Essential JS 2) quickstart project from GitHub.
git clone https://github.com/SyncfusionExamples/ej2-quickstart-webpack ej2-quickstartAfter cloning the application in the ej2-quickstart folder, run the following command line to navigate to the ej2-quickstart folder.
cd ej2-quickstartAdd Syncfusion JavaScript packages
Syncfusion JavaScript (Essential JS 2) packages are available on the npmjs.com public registry. You can install all Syncfusion JavaScript (Essential JS 2) controls in a single @syncfusion/ej2 package or individual packages for each control.
The quickstart application is preconfigured with the dependent @syncfusion/ej2 package in the ~/package.json file. Use the following command to install the dependent npm packages from the command prompt.
npm installAdd Range Navigator to the Project
Open the project in Visual Studio Code and add the Range navigator to the application.
Add the HTML div tag with its id attribute as element in your ~/src/index.html file to initialize the Range Navigator.
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Range Navigator</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="TypeScript UI Controls" />
<meta name="author" content="Syncfusion" />
....
....
</head>
<body>
<!--container which is going to render the RangeNavigator-->
<div id='element'>
</div>
</body>
</html>Import the Range navigator component into src/app/app.ts to instantiate and render the Range Navigator.
import { RangeNavigator } from '@syncfusion/ej2-charts';
// initialize RangeNavigator component
let range: RangeNavigator = new RangeNavigator();
// render initialized RangeNavigator
range.appendTo('#element');Run the Application
The quickstart project is configured to compile and run the application in the browser. Use the following command to run the application.
npm startThe following example shows a basic Range Navigator.
import { RangeNavigator} from "@syncfusion/ej2-charts";
let range: RangeNavigator = new RangeNavigator();
range.appendTo('#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="margin-top: 125px">
<div id='element'></div>
</div>
</body>
</html>Module Injection
To create range navigator with additional features, inject the required modules. The following modules are used to extend Range Navigator’s basic functionality.
-
AreaSeries- Inject this module to use area series. -
DateTime- Inject this module to use date time axis. -
RangeTooltip- Inject this module to show the tooltip.
Now import the above-mentioned modules from the chart package and inject them into the Range navigator component using RangeNavigator.Inject method.
import { RangeNavigator, AreaSeries, DateTime, RangeTooltip }from '@syncfusion/ej2-charts';
RangeNavigator.Inject(AreaSeries, DateTime, RangeTooltip);Populate Range Navigator with Data
Now, we are going to provide data to the range navigator. Add a series object to the range navigator by using series property. Now map the field names x and y in the JSON data to the xName and yName properties 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.
import { RangeNavigator, AreaSeries, DateTime} from "@syncfusion/ej2-charts";
RangeNavigator.Inject(AreaSeries, DateTime);
import { datasrc } from "./datasource.ts";
let range: RangeNavigator = new RangeNavigator({
valueType: 'DateTime',
value: [new Date('2017-09-01'), new Date('2018-02-01')],
labelFormat: 'MMM-yy',
series: [{
dataSource: datasrc, xName: 'x', yName: 'y', type: 'Area', width: 2,
}],
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="margin-top: 125px">
<div id='element'></div>
</div>
</body>
</html>Note: Get data from here.
The sample should look like our default, don’t worry about the gradient color, let it take the default color.
Enable Tooltip
The tooltip is useful to show the selected data. You can enable tooltip by setting the enable property to true in tooltip object and by injecting RangeTooltipService module using RangeNavigator.Inject(RangeTooltip) method.
import { RangeNavigator, AreaSeries, DateTime, RangeTooltip} from "@syncfusion/ej2-charts";
RangeNavigator.Inject(AreaSeries, DateTime, RangeTooltip);
import { datasrc } from "./datasource.ts";
let range: RangeNavigator = new RangeNavigator({
valueType: 'DateTime',
value: [new Date('2017-09-01'), new Date('2018-02-01')],
tooltip: { enable: true, displayMode: 'Always' },
labelFormat: 'MMM-yy',
series: [{
dataSource: datasrc, xName: 'x', yName: 'y', type: 'Area', width: 2,
}],
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style="margin-top: 125px">
<div id='element'></div>
</div>
</body>
</html>