Getting Started with EJ2 JavaScript Timeline

14 Sep 20263 minutes to read

The Essential® JS 2 for JavaScript (global script) is an ES5 formatted pure JavaScript framework that can be directly used in latest web browsers.

Setup for local environment

Refer to the following steps to set up your local environment.

Step 1: Create a root folder named my-app for your application.

Step 2: Create a my-app/resources folder to store local scripts and styles files.

Step 3: Open Visual Studio Code and create my-app/index.js and my-app/index.html files to initialize the Essential® JS 2 Timeline control.

Control Initialization

The Essential® JS 2 JavaScript controls can be initialized by using below css styles and scripts

Add Syncfusion® Timeline CSS Styles and Scripts

Include the following CSS and JavaScript files from CDN in the <head> section of the index.html file. The ej2-base script is the required dependency package for the Timeline component.

Styles(CSS):

https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/timeline/index.css

Scripts (javascript):

https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/dist/global/ej2-base.min.js
https://cdn.syncfusion.com/ej2/35.1.37/ej2-layouts/dist/global/ej2-layouts.min.js

Adding Timeline component to the application

Add the div element and initiate the Essential® JS 2 Timeline control in the index.html by using the following code.

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 - Timeline</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="description" content="Essential JS 2">
    <meta name="author" content="Syncfusion">
    <link href="https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/timeline/index.css" rel="stylesheet" />
        type="text/css" />

    <!-- Essential JS 2 Timeline's dependent global script -->
    <script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-base/dist/global/ej2-base.min.js"
        type="text/javascript"></script>
    <script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-layouts/dist/global/ej2-layouts.min.js"
        type="text/javascript"></script>

</head>

<body>

    <div id="container" style="height: 300px;">
        <!--Element to render the Timeline control-->
        <div id="timeline"></div>
    </div>

    <script>
        // Initialize Timeline control
        var timeline = new ej.layouts.Timeline({
            items: [{}, {}, {}, {}],
        });
        // Render initialized Timeline.
        timeline.appendTo("#timeline");
    </script>
    <style>
        #container {
            margin-top: 30px;
            padding: 30px;
        }
    </style>
</body>

</html>