Stacked column Chart in EJ2 JavaScript control

28 Sep 202317 minutes to read

100% Stacked column

To render a 100% stacked column series, use series type as StackingColumn100 and inject StackingColumnSeries module using Chart.Inject(StackingColumnSeries) method.

var chartData = [
    { x: new Date(2006, 0, 1), y: 900, y1: 190, y2: 250, y3: 150 },
    { x: new Date(2007, 0, 1), y: 544, y1: 226, y2: 145, y3: 120 },
    { x: new Date(2008, 0, 1), y: 880, y1: 194, y2: 190, y3: 115 },
    { x: new Date(2009, 0, 1), y: 675, y1: 250, y2: 220, y3: 125 },
    { x: new Date(2010, 0, 1), y: 765, y1: 222, y2: 225, y3: 132 },
    { x: new Date(2011, 0, 1), y: 679, y1: 181, y2: 135, y3: 137 },
    { x: new Date(2012, 0, 1), y: 770, y1: 128, y2: 152, y3: 110 },
];
var chart = new ej.charts.Chart({
        primaryXAxis: {
            title: 'Years',
            interval: 1,
            valueType: 'DateTime',
            labelFormat: 'y'
        },
        primaryYAxis:
        {
            title: 'GDP (%) Per Annum',
            rangePadding: 'None',
            labelFormat: '{value}%',
        },
        series: [
            {
                dataSource: chartData, xName: 'x', yName: 'y',
                //Series type as 100% stacked column series
                type: 'StackingColumn100',
                name: 'UK',
            }, {
                dataSource: chartData, xName: 'x', yName: 'y1',
                 type: 'StackingColumn100', name: 'Germany',
            }, {
                dataSource: chartData, xName: 'x', yName: 'y2',
                 type: 'StackingColumn100', name: 'France',

            }, {
               dataSource: chartData, xName: 'x', yName: 'y3',
                 type: 'StackingColumn100', name: 'Italy',

            }
        ],
        title: 'Gross Domestic Product Growth'
}, '#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://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

100% Cylindrical stacked column chart

To render a 100% cylindrical stacked column chart, set the columnFacet property to Cylinder in the chart series.

var cylindricalData = [
    { x: new Date(2006, 0, 1), y: 900, y1: 190, y2: 250, y3: 150 },
    { x: new Date(2007, 0, 1), y: 544, y1: 226, y2: 145, y3: 120 },
    { x: new Date(2008, 0, 1), y: 880, y1: 194, y2: 190, y3: 115 },
    { x: new Date(2009, 0, 1), y: 675, y1: 250, y2: 220, y3: 125 },
    { x: new Date(2010, 0, 1), y: 765, y1: 222, y2: 225, y3: 132 },
    { x: new Date(2011, 0, 1), y: 679, y1: 181, y2: 135, y3: 137 },
    { x: new Date(2012, 0, 1), y: 770, y1: 128, y2: 152, y3: 110 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        title: 'Years',
        interval: 1,
        valueType: 'DateTime',
        labelFormat: 'y'
    },
    primaryYAxis:
    {
        title: 'GDP (%) Per Annum',
        rangePadding: 'None',
        labelFormat: '{value}%',
    },
    //Series type as 100% stacked column series with cylinderical shape
    series: [
        {
            dataSource: cylindricalData, xName: 'x', yName: 'y',
            type: 'StackingColumn100', columnFacet: 'Cylinder', name: 'UK'
        },
        {
            dataSource: cylindricalData, xName: 'x', yName: 'y1',
            type: 'StackingColumn100', columnFacet: 'Cylinder', name: 'Germany'
        },
        {
            dataSource: cylindricalData, xName: 'x', yName: 'y2',
            type: 'StackingColumn100', columnFacet: 'Cylinder', name: 'France'
        },
        {
            dataSource: cylindricalData, xName: 'x', yName: 'y3',
            type: 'StackingColumn100', columnFacet: 'Cylinder', name: 'Italy'
        }
    ],
    title: 'Gross Domestic Product Growth'
}, '#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://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Series customization

The following properties can be used to customize the column series.

var chartData = [
    { x: new Date(2006, 0, 1), y: 900, y1: 190, y2: 250, y3: 150 },
    { x: new Date(2007, 0, 1), y: 544, y1: 226, y2: 145, y3: 120 },
    { x: new Date(2008, 0, 1), y: 880, y1: 194, y2: 190, y3: 115 },
    { x: new Date(2009, 0, 1), y: 675, y1: 250, y2: 220, y3: 125 },
    { x: new Date(2010, 0, 1), y: 765, y1: 222, y2: 225, y3: 132 },
    { x: new Date(2011, 0, 1), y: 679, y1: 181, y2: 135, y3: 137 },
    { x: new Date(2012, 0, 1), y: 770, y1: 128, y2: 152, y3: 110 },
];
var chart = new ej.charts.Chart({
        primaryXAxis: {
            title: 'Years',
            interval: 1,
            valueType: 'DateTime',
            labelFormat: 'y'
        },
        primaryYAxis:
        {
            title: 'GDP (%) Per Annum',
            rangePadding: 'None',
            labelFormat: '{value}%',
        },
        series: [
            {
                dataSource: chartData, xName: 'x', yName: 'y1',
                 type: 'StackingColumn100', name: 'Germany',border: { width: 1.5, color: 'red'}
            }, {
                dataSource: chartData, xName: 'x', yName: 'y2',
                 type: 'StackingColumn100', name: 'France', border: { width: 1.5, color: 'yellow'}

            }, {
               dataSource: chartData, xName: 'x', yName: 'y3',
                 type: 'StackingColumn100', name: 'Italy', border: { width: 1.5, color: 'blue'}

            }
        ],
        title: 'Gross Domestic Product Growth'
}, '#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://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div id="container">
        <div id="element"></div>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

See also