Grid data chart in Angular Chart component

20 Sep 20226 minutes to read

You can visualize the data that returned by grid in chart.

To visualize the data in chart, follow the given steps:

Step 1:

Initialize the grid with datasource.

Step 2:

By using the grid’s actionComplete event and getCurrentViewRecords method, you can get the current page records.
By using the grid’s databound event, you can update the current page records into the chart’s datasource and visualize the grid data in chart.

import { Component, OnInit, ViewChild } from '@angular/core';
import { IDragCompleteEventArgs, ChartComponent } from '@syncfusion/ej2-angular-charts';
import { GridComponent, ActionEventArgs } from '@syncfusion/ej2-angular-grids';
import { Query, DataManager } from '@syncfusion/ej2-data';
import { orderData } from 'datasource.ts';
    selector: 'app-container',
    `<ejs-grid #grid [dataSource]='data' [allowPaging]="true" [pageSettings]='pageSettings' (dataBound)='dataBound()'
                    <e-column field='OrderDate' headerText='Order Date' width=130 format='yMd' textAlign='right'></e-column>
                    <e-column field='Freight' width=120 format='C2' textAlign='right'></e-column>
    <ejs-chart #chart id="chart-container" [primaryXAxis]='primaryXAxis'[primaryYAxis]='primaryYAxis' [title]='title'>
            <e-series  type='Line' xName='OrderDate' yName='Freight' name='dataview' [marker]='marker'></e-series>>

export class AppComponent implements OnInit {
    public primaryXAxis: Object;
    public chartData: Object[];
    public data: Object[];
    public title: string;
    public marker: Object;
    public primaryYAxis: Object;
    public pageSettings: Object;
    public chart: ChartComponent;
    public grid: GridComponent;
    ngOnInit(): void { = new DataManager(orderData as JSON[]).executeLocal(new Query().take(100));
        this.pageSettings = { pageSize: 10 };
    dataBound() {
           this.chart.primaryXAxis = {
            valueType: 'DateTime',
          this.chart.series[0].marker = { visible: true}
          this.chart.series[0].xName = 'OrderDate';
          this.chart.series[0].yName = 'Freight';
          this.chart.series[0].dataSource = this.grid.getCurrentViewRecords();
  public actionComplete(args: ActionEventArgs):void {
                if (args.requestType === 'paging') {
                 this.chart.series[0].dataSource =  this.grid.getCurrentViewRecords();
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { ChartModule } from '@syncfusion/ej2-angular-charts';
import { GridModule } from '@syncfusion/ej2-angular-grids';
import { PageService, SortService, FilterService, GroupService  } from '@syncfusion/ej2-angular-grids';
import { AccumulationChartModule } from '@syncfusion/ej2-angular-charts';
import { PieSeriesService, AccumulationTooltipService, AccumulationDataLabelService } from '@syncfusion/ej2-angular-charts';
import { LineSeriesService, DateTimeService, DataLabelService,StackingColumnSeriesService,CategoryService, ChartShape,
       StepAreaSeriesService,SplineSeriesService, ChartAnnotationService, LegendService, TooltipService, StripLineService,
    } from '@syncfusion/ej2-angular-charts';

 * Module
    imports: [
        BrowserModule, ChartModule, AccumulationChartModule, GridModule
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [ LineSeriesService, DateTimeService, DataLabelService, StackingColumnSeriesService,CategoryService,
               StepAreaSeriesService, SplineSeriesService, ChartAnnotationService, LegendService, TooltipService, StripLineService,
               PieSeriesService, AccumulationTooltipService, AccumulationDataLabelService, SelectionService,ScatterSeriesService
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';