Multiple series in JavaScript Charts

The chart supports rendering multiple data series simultaneously, allowing comparison of different datasets within a single chart. You can also combine different series types and bind complex data structures to series.

Multiple series

You can add multiple series to the chart by using the series property. The series are rendered in the order they are added to the series array, and this order also determines the legend display sequence.

var chartData = [
      { country: "USA", gold: 50, silver: 70, bronze: 45 },
      { country: "China", gold: 40, silver: 60, bronze: 55 },
      { country: "Japan", gold: 70, silver: 60, bronze: 50 },
      { country: "Australia", gold: 60, silver: 56, bronze: 40 },
      { country: "France", gold: 50, silver: 45, bronze: 35 },
      { country: "Germany", gold: 40, silver: 30, bronze: 22 },
      { country: "Italy", gold: 40, silver: 35, bronze: 37 },
      { country: "Sweden", gold: 30, silver: 25, bronze: 27 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        valueType: 'Category',
        title: 'Countries'
    },
    primaryYAxis: {
        minimum: 0, maximum: 80,
        interval: 20, title: 'Medals'
    },
    series:[{
        dataSource: chartData,
        xName: 'country', yName: 'gold',
        name: 'Gold', type: 'Column'
    }, {
        dataSource: chartData,
        xName: 'country', yName: 'silver',
        name: 'Silver', type: 'Column'
    }, {
        dataSource: chartData,
        xName: 'country', yName: 'bronze',
        name: 'Bronze', type: 'Column'
    }],
    title: 'Olympic Medals'
}, '#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/35.2.12/dist/ej2.min.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>

Combination series

The chart allows you to render a combination of different series, such as Column, Line, Area, etc. This is useful for comparing datasets that have different scales or trends. For the complete list of available series types, see the chart types documentation.

Note: Bar series cannot be combined with any other series, because the axis orientation is different from other series.

var chartData = [
    { x: '2005', y: 1.2, y1: 0.5, y2: 0.7, y3: -0.8, y4: 1.5 },
    { x: '2006', y: 1, y1: 0.5, y2: 1.4, y3: 0, y4: 2.3 },
    { x: '2007', y: 1, y1: 0.5, y2: 1.5, y3: -1, y4: 2 },
    { x: '2008', y: 0.25, y1: 0.35, y2: 0.35, y3: -.35, y4: 0.1 },
    { x: '2009', y: 0.1, y1: 0.9, y2: -2.7, y3: -0.3, y4: -2.7 },
    { x: '2010', y: 1, y1: 0.5, y2: 0.5, y3: -0.5, y4: 1.8 },
    { x: '2011', y: 0.1, y1: 0.25, y2: 0.25, y3: 0, y4: 2 },
    { x: '2012', y: -0.25, y1: -0.5, y2: -0.1, y3: -0.4, y4: 0.4 },
    { x: '2013', y: 0.25, y1: 0.5, y2: -0.3, y3: 0, y4: 0.9 },
    { x: '2014', y: 0.6, y1: 0.6, y2: -0.6, y3: -0.6, y4: 0.4 },
    { x: '2015', y: 0.9, y1: 0.5, y2: 0, y3: -0.3, y4: 1.3 }
];
var chart = new ej.charts.Chart({
        primaryXAxis: {
            title: 'Years',
            interval: 1,
            labelIntersectAction : 'Rotate45',
            valueType: 'Category'
        },
        primaryYAxis:
        {
            title: 'Growth',
            minimum: -3, maximum: 3, interval: 1
        },
        series: [
            {
                type: 'StackingColumn', dataSource: chartData,
                xName: 'x', yName: 'y', name: 'Private Consumption'
            }, {
                type: 'StackingColumn', dataSource: chartData,
                xName: 'x', yName: 'y1', name: 'Government Consumption'
            }, {
                type: 'StackingColumn', dataSource: chartData,
                xName: 'x', yName: 'y2', name: 'Investment'
            }, {
                type: 'StackingColumn', dataSource: chartData,
                xName: 'x', yName: 'y3', name: 'Net Foreign Trade'

            }, {
                type: 'Line',  name: 'GDP',
                dataSource: chartData, xName: 'x', yName: 'y4',
                width: 2, opacity: 0.6,
                marker: {
                    visible: true,
                    width: 10, opacity: 0.6,
                    height: 10
                },
            }
        ],
        title: 'Annual Growth GDP in France'
}, '#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/35.2.12/dist/ej2.min.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>

Enable complex property in series

Set the enableComplexProperty value to true in the series to bind complex (nested) data to the chart.

var chartData = [
    { year: '2005', consumption: { private: 1.2, government: 0.5 }, investment: { value: 0.7 }, trade: { net: -0.8 }, gdp: { growth: 1.5 } },
    { year: '2006', consumption: { private: 1, government: 0.5 }, investment: { value: 1.4 }, trade: { net: 0 }, gdp: { growth: 2.3 } },
    { year: '2007', consumption: { private: 1, government: 0.5 }, investment: { value: 1.5 }, trade: { net: -1 }, gdp: { growth: 2 } },
    { year: '2008', consumption: { private: 0.25, government: 0.35 }, investment: { value: 0.35 }, trade: { net: -0.35 }, gdp: { growth: 0.1 } },
    { year: '2009', consumption: { private: 0.1, government: 0.9 }, investment: { value: -2.7 }, trade: { net: -0.3 }, gdp: { growth: -2.7 } },
    { year: '2010', consumption: { private: 1, government: 0.5 }, investment: { value: 0.5 }, trade: { net: -0.5 }, gdp: { growth: 1.8 } },
    { year: '2011', consumption: { private: 0.1, government: 0.25 }, investment: { value: 0.25 }, trade: { net: 0 }, gdp: { growth: 2 } },
    { year: '2012', consumption: { private: -0.25, government: -0.5 }, investment: { value: -0.1 }, trade: { net: -0.4 }, gdp: { growth: 0.4 } },
    { year: '2013', consumption: { private: 0.25, government: 0.5 }, investment: { value: -0.3 }, trade: { net: 0 }, gdp: { growth: 0.9 } },
    { year: '2014', consumption: { private: 0.6, government: 0.6 }, investment: { value: -0.6 }, trade: { net: -0.6 }, gdp: { growth: 0.4 } },
    { year: '2015', consumption: { private: 0.9, government: 0.5 }, investment: { value: 0 }, trade: { net: -0.3 }, gdp: { growth: 1.3 } }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        title: 'Years',
        interval: 1,
        labelIntersectAction: 'Rotate45',
        valueType: 'Category'
    },
    primaryYAxis: {
        title: 'Growth',
        minimum: -3,
        maximum: 3,
        interval: 1
    },
    series: [
        {
            type: 'StackingColumn',
            dataSource: chartData,
            enableComplexProperty: true,
            xName: 'year',
            yName: 'consumption.private',
            name: 'Private Consumption'
        },
        {
            type: 'StackingColumn',
            dataSource: chartData,
            enableComplexProperty: true,
            xName: 'year',
            yName: 'consumption.government',
            name: 'Government Consumption'
        },
        {
            type: 'StackingColumn',
            dataSource: chartData,
            enableComplexProperty: true,
            xName: 'year',
            yName: 'investment.value',
            name: 'Investment'
        },
        {
            type: 'StackingColumn',
            dataSource: chartData,
            enableComplexProperty: true,
            xName: 'year',
            yName: 'trade.net',
            name: 'Net Foreign Trade'
        },
        {
            type: 'Line',
            dataSource: chartData,
            enableComplexProperty: true,
            xName: 'year',
            yName: 'gdp.growth',
            name: 'GDP',
            width: 2,
            opacity: 0.6,
            marker: {
                visible: true,
                width: 10,
                height: 10,
                opacity: 0.6
            }
        }
    ],
    title: 'Annual GDP Growth in France'
}, '#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/35.2.12/dist/ej2.min.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>

Troubleshooting: If series do not appear as expected, verify that each series has a unique name, the dataSource is correctly bound, and the xName/yName properties match your data structure. For combination charts, ensure all series use compatible axis orientations.

See also