Articles in this section
Category / Section

How to get started easily with Syncfusion Angular 11 Sparkline Charts?

3 mins read

The Essential JS 2 Sparkline is used to present the general shape of variation in some measurement in a simple and highly condensed way. It is a very small line chart, typically drawn without axes or co-ordinates. Its type includes line, area, WinLoss, and column. This KB article explains how to easily integrate Syncfusion Angular Sparkline in an Angular 11 application and how to enable its commonly used features using services.

Prerequisites

 

Before starting, you need the following items to create Angular Sparkline in an Angular 11 Application:

 
Installation and application creation

 

  1. Install Angular CLI using the following command.

 

npm install @angular/cli@11.2.3

 

 

Note:

If you would like to follow and run the application in Angular 4 or Angular 5 or Angular 6, you need to replace the CLI command version number with corresponding Angular version number

 

npm  install -g @angular/cli@<CLI VERSION>

 

 

  1. Create an Angular 11 application using Angular CLI.

 

ng new angular11-app

cd angular-app

 

  1. Serve the Angular 11 application using the following command.

 

ng serve --open

 

Listen to the application in localhost:4200. Your application will serve in browser. Refer to the following screenshot for Angular 11 version.

Angular-app

 

Integration of Angular Sparkline Charts

 

  1. After running the Angular 11 application successfully, configure the Angular Sparkline Charts in this application. Install Angular Sparkline Charts and EJ2 package using the following command.
    npm install @syncfusion/ej2-angular-charts --save
    
    npm install @syncfusion/ej2 --save
    
    

 

The --save command instructs NPM to include the Sparkline Charts package inside the dependencies section of the package.json.

  1. Import SparklinechartsModule from the installed package in app/app.module.ts.

 

import { BrowserModule } from '@angular/platform-browser';

import { NgModule } from '@angular/core';

import { SparklineModule } from '@syncfusion/ej2-angular-charts;

import { AppComponent } from './app.component';

 

@NgModule({

  declarations: [

    AppComponent

  ],

imports: [

    BrowserModule,

    SparklineModule

  ],

providers: [],

bootstrap: [AppComponent]

})

export class AppModule { }

 

  1. Refer the CSS file for Angular Sparkline Charts in style.css.

 

Import “../node_modules/@syncfusion/ej2/material.css”

 

  1. Add the Angular Sparkline component in app.component.html.

 

<ejs-sparkline></ejs-sparkline>

 

  1. Now, add the data source for Sparkline Charts in app.component.ts.

 

public pausData: object[] = [

    { x: 0, xval: '2005', yval: 20090440 },

    { x: 1, xval: '2006', yval: 20264080 },

    { x: 2, xval: '2007', yval: 20434180 },

    { x: 3, xval: '2008', yval: 21007310 },

    { x: 4, xval: '2009', yval: 21262640 },

    { x: 5, xval: '2010', yval: 21515750 },

    { x: 6, xval: '2011', yval: 21766710 },

    { x: 7, xval: '2012', yval: 22015580 },

    { x: 8, xval: '2013', yval: 22262500 },

    { x: 9, xval: '2014', yval: 22507620 },

];

 

 

  1. After adding the data source, define the Sparkline Charts in app.component.html.

 

<ejs-sparkline id="paus" height="50px" width="150px" lineWidth=2         valueType="Category" fill="#3C78EF" negativePointColor="red" [dataSource]="pausData"  xName="xval" yName="yval" format='n' useGroupingSeparator="true">

</ejs-sparkline>

<ejs-sparkline id="aaus" height="50px" width="150px" lineWidth=2 v       valueType="Category" fill="#3C78EF"

type="Area" negativePointColor="red" [dataSource]="pausData" xName="xval" yName="yval">

</ejs-sparkline>

<ejs-sparkline id="waus" height="50px" width="150px" lineWidth=2 valueType="Category" fill="#3C78EF" type="WinLoss" negativePointColor="red" [dataSource]="pausData"  xName="xval" yName="yval">

</ejs-sparkline>

 

<ejs-sparkline id="caus" height="50px" width="150px" lineWidth=2 valueType="Category" fill="#3C78EF"  type="Column" [axisSettings]="minAus" negativePointColor="red" [dataSource]="pausData" xName="xval" yName="yval"></ejs-sparkline>

 

  1. Now, serve the application using the following command.

 

ng serve --open

 

After all the files have been compiled successfully, it will serve the site at localhost:4200.

The following screenshot illustrates Sparkline Charts.

Sparkline

Summary

 

To know more about Sparkline Charts, check our Angular Sparkline Charts features from this page. If you have any queries or require clarifications. Please let us know in comments below. You can also contact us through our Support forum or Direct-Trac. We are happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied