Search results

Grid Data in Chart in JavaScript (ES5) Chart control

21 Oct 2021 / 2 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.

Copied to clipboard
var chart = new ej.charts.Chart();
    var data = new;
     var grid = new ej.grids.Grid({
            dataSource: data,
            allowPaging: true,
            pageSettings: { pageSize: 10 },
            columns: [
                { field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'right' },
                { field: 'Freight', width: 120, format: 'C2', textAlign: 'right' }
        dataBound: function() {
        chart = new ej.charts.Chart({
            //Initializing Primary X Axis
            primaryXAxis: {
            valueType: 'DateTime',
            series: [
                type: 'Column',
                dataSource: grid.getCurrentViewRecords(),
                xName: 'OrderDate', width: 2, marker: {
                    visible: true,
                    width: 10,
                    height: 10
                yName: 'Freight', name: 'Germany',

          }, '#Chart');
         actionComplete: function(args)  {
                if (args.requestType === 'paging') {
                 chart.series[0].dataSource =  grid.getCurrentViewRecords();
        }, '#Grid');
Copied to clipboard
<!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="" rel="stylesheet">
    <link href="" rel="stylesheet">
<script src="" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>

    <div class="col-sm-8">
            <div class="row">
                <div class="col-sm-4" style="width:200px; height:300px;float: left">
                  <div id="Grid">
                <div class="col-sm-4">
                  <div id="container">
                    <div id="Chart" style="width:250px; height:300px;float: right">
var ele = document.getElementById('container');
if(ele) { = "visible";
<script src="index.js" type="text/javascript"></script>