Gradient in JavaScript Chart control

18 Nov 201824 minutes to read

Gradients add depth and modern styling to charts by smoothly blending multiple colors. The Charts component supports two gradient types:

  • Linear gradient
  • Radial gradient

Gradients can be applied to:

  • Series
  • Trendlines
  • Technical Indicators

Linear gradient

A linear gradient blends color along side a straight path from a defined start point to an end point. Configure it by adding linearGradient inside the target element (Series, Trendlines or Indicators) and define one or more color stops that control how colors transition across the gradient. Set the start and end positions of the gradient using x1, y1, x2 and y2 properties. The gradient color stop values such as offset, color, opacity, lighten and brighten are set using the gradientColorStop property.

In the linearGradient:

  • x1 - Sets the horizontal start position of the gradient (0 to 1).
  • y1 - Sets the vertical start position of the gradient (0 to 1).
  • x2 - Sets the horizontal end position of the gradient (0 to 1).
  • y2 - Sets the vertical end position of the gradient (0 to 1).

In the gradientColorStop:

  • offset - Specifies the position of the color stop along the gradient (0 to 100).
  • color - Sets the color at the stop.
  • opacity - Defines the transparency of the stop (0 to 1).
  • lighten - Adjusts lightness at the stop. Positive values lighten the color. Range: 0 to 1.
  • brighten - Adjusts brightness at the stop. Positive values increase brightness; negative values decrease it. Ranges: -1 to 1.

Series

Apply a linear gradient to a series by adding linearGradient inside the target Series. The same gradient is applied to the series markers, legend symbol and tooltip marker for visual consistency.

var SalesData = [
    { Month: "Jan", Amount: 78 },
    { Month: "Feb", Amount: 88 },
    { Month: "Mar", Amount: 99 },
    { Month: "Apr", Amount: 92 },
    { Month: "May", Amount: 95 },
    { Month: "Jun", Amount: 102 },
    { Month: "Jul", Amount: 110 },
    { Month: "Aug", Amount: 105 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        valueType: 'Category',
    },
    primaryYAxis: {
        labelFormat: '${value}k'
    },
    series: [{
        dataSource: SalesData,
        xName: 'Month', yName: 'Amount',
        name: 'Sales',
        type: 'Column',
        linearGradient: {
            x1: 0, y1: 0,
            x2: 0, y2: 1,
            gradientColorStop: [
                { color: '#4F46E5', offset: 0, opacity: 1, lighten: 0, brighten: 0 },
                { color: '#22D3EE', offset: 100, opacity: 0.95, lighten: 0, brighten: 0.9 }
            ]
        },
        marker: {
            visible: true, isFilled: true,
            dataLabel: {
                visible: true
            }
        },
    }],
    tooltip: {
        enable: true
    },
    legendSettings: {
        visible: true
    },
    title: 'Monthly Sales Performance'
}, '#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/34.1.29/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>

Trendlines

Apply a linear gradient to a trendline by adding linearGradient inside the target Trendline.

var OrdersData = [
    { Month: "Jan", Orders: 24 },
    { Month: "Feb", Orders: 30 },
    { Month: "Mar", Orders: 27 },
    { Month: "Apr", Orders: 34 },
    { Month: "May", Orders: 41 },
    { Month: "Jun", Orders: 37 },
    { Month: "Jul", Orders: 49 },
    { Month: "Aug", Orders: 45 },
    { Month: "Sep", Orders: 39 },
    { Month: "Oct", Orders: 46 },
    { Month: "Nov", Orders: 54 },
    { Month: "Dec", Orders: 52 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        valueType: 'Category',
        majorGridLines: {
            width: 0
        }
    },
    primaryYAxis: {
        lineStyle: {
            width: 0
        },
        majorTickLines: {
            width: 0
        }
    },
    series: [{
        dataSource: OrdersData,
        xName: 'Month', yName: 'Orders',
        type: 'Spline',
        marker: {
            visible: true
        },
        trendlines: [
            {
                type: 'Linear',
                width: 3,
                name: 'Trend',
                linearGradient: {
                    x1: 0, y1: 0,
                    x2: 1, y2: 0,
                    gradientColorStop: [
                        { color: '#F97316', offset: 0, opacity: 1 },
                        { color: '#4F46E5', offset: 100, opacity: 1 }
                    ]
                }
            }
        ]
    }],
    legendSettings: {
        visible: true
    },
    title: 'Retail Orders Processed'
}, '#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/34.1.29/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>

Technical Indicators

Apply a linear gradient to a technical indicator by adding linearGradient inside the target Indicator.

var PriceSeries = [
    { Date: new Date(2025, 0, 1), Open: 103.9, High: 106.8, Low: 102.5, Close: 105.6, Volume: 182540000 },
    { Date: new Date(2025, 1, 1), Open: 105.2, High: 108.1, Low: 103.4, Close: 106.9, Volume: 176310000 },
    { Date: new Date(2025, 2, 1), Open: 106.7, High: 110.6, Low: 105.1, Close: 108.7, Volume: 189250000 },
    { Date: new Date(2025, 3, 1), Open: 108.9, High: 110.9, Low: 106.8, Close: 107.6, Volume: 171900000 },
    { Date: new Date(2025, 4, 1), Open: 107.8, High: 112.3, Low: 106.9, Close: 111.4, Volume: 196700000 },
    { Date: new Date(2025, 5, 1), Open: 111.2, High: 114.9, Low: 110.0, Close: 113.6, Volume: 205600000 },
    { Date: new Date(2025, 6, 1), Open: 113.5, High: 117.3, Low: 112.2, Close: 116.0, Volume: 213400000 },
    { Date: new Date(2025, 7, 1), Open: 116.1, High: 119.2, Low: 114.6, Close: 118.1, Volume: 221900000 },
    { Date: new Date(2025, 8, 1), Open: 117.9, High: 120.7, Low: 116.0, Close: 116.8, Volume: 198300000 },
    { Date: new Date(2025, 9, 1), Open: 116.7, High: 121.6, Low: 116.1, Close: 119.9, Volume: 234600000 },
    { Date: new Date(2025, 10, 1), Open: 120.2, High: 123.9, Low: 118.8, Close: 122.5, Volume: 226100000 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        title: 'Months',
        valueType: 'DateTime',
        intervalType: 'Months',
        labelFormat: 'MMM yyyy',
        edgeLabelPlacement: 'Shift',
        majorGridLines: {
            width: 0
        }
    },
    primaryYAxis: {
        title: 'Price (USD)',
        labelFormat: '${value}',
        minimum: 90, maximum: 130,
        interval: 10,
        lineStyle: {
            width: 0
        },
        majorTickLines: { width: 0 }
    },
    series: [{
        dataSource: PriceSeries, width: 2,
        xName: 'Date', yName: 'y', low: 'Low', high: 'High', close: 'Close', volume: 'Volume', open: 'Open',
        name: 'Equity Price',
        type: 'Candle'
    }],
    indicators: [{
        type: 'Ema', field: 'Close', seriesName: 'Equity Price', xName: 'Date', width: 2,
        period: 3,
        linearGradient: {
            x1: 0, y1: 0,
            x2: 1, y2: 0,
            gradientColorStop: [
                { color: '#7C3AED', offset: 0, opacity: 1 },
                { color: '#F59E0B', offset: 100, opacity: 1 }
            ]
        }
    }],
    tooltip: {
        enable: true
    },
    legendSettings: {
        visible: false
    },
    title: 'Equity Price - Jan-Nov 2025'
}, '#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/34.1.29/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>

Radial gradient

A radial gradient blends colors outward from a central point, creating a circular or elliptical color progression. Configure it by adding radialGradient inside the target element (Series, Trendline, or Indicator) and define one or more color stops to control how colors transition from the center to the outer edge. Set the gradient’s center, optional focal point, and radius using radialGradient properties. The color stop values such as offset, color, opacity, lighten, and brighten are set using the gradientColorStop property.

In the radialGradient:

  • cx - Sets the normalized horizontal center of the gradient (0 to 1).
  • cy - Sets the normalized vertical center of the gradient (0 to 1).
  • fx - Sets the normalized horizontal focal point from which the gradient appears to originate (0 to 1).
  • fy - Sets the normalized vertical focal point (0 to 1).
  • r - Sets the normalized radius of the gradient circle (0 to 1).

In the gradientColorStop:

  • offset - Specifies the position of the color stop along the gradient (0 to 100).
  • color - Sets the color at the stop.
  • opacity - Defines the transparency of the stop (0 to 1).
  • lighten - Adjusts lightness at the stop. Positive values lighten the color. Range: 0 to 1.
  • brighten - Adjusts brightness at the stop. Positive values increase brightness; negative values decrease it. Ranges: -1 to 1.

Series

Apply a radial gradient to a series by adding radialGradient inside the target Series. The same gradient is applied to the series markers, legend symbol and tooltip marker for visual consistency.

var SalesData = [
    { Month: "Jan", Amount: 78 },
    { Month: "Feb", Amount: 88 },
    { Month: "Mar", Amount: 99 },
    { Month: "Apr", Amount: 92 },
    { Month: "May", Amount: 95 },
    { Month: "Jun", Amount: 102 },
    { Month: "Jul", Amount: 110 },
    { Month: "Aug", Amount: 105 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        valueType: 'Category',
    },
    primaryYAxis: {
        labelFormat: '${value}k'
    },
    series: [{
        dataSource: SalesData,
        xName: 'Month', yName: 'Amount',
        name: 'Sales',
        type: 'Column',
        radialGradient: {
            cx: 0.5, cy: 0.5,
            fx: 0.5, fy: 0.5, r: 0.5,
            gradientColorStop: [
                {color: '#FFFF00', offset: 0, opacity: 1, lighten: 0, brighten: 0},
                {color: '#7C3AED', offset: 100, opacity: 0.95, lighten: 0, brighten: 0.9}
            ]
        },
        marker: {
            visible: true, isFilled: true,
            dataLabel: {
                visible: true
            }
        },
    }],
    tooltip: {
        enable: true
    },
    legendSettings: {
        visible: true
    },
    title: 'Monthly Sales Performance'
}, '#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/34.1.29/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>

Trendlines

Apply a radial gradient to a trendline by adding radialGradient inside the target Trendline.

var OrdersData = [
    { Month: "Jan", Orders: 24 },
    { Month: "Feb", Orders: 30 },
    { Month: "Mar", Orders: 27 },
    { Month: "Apr", Orders: 34 },
    { Month: "May", Orders: 41 },
    { Month: "Jun", Orders: 37 },
    { Month: "Jul", Orders: 49 },
    { Month: "Aug", Orders: 45 },
    { Month: "Sep", Orders: 39 },
    { Month: "Oct", Orders: 46 },
    { Month: "Nov", Orders: 54 },
    { Month: "Dec", Orders: 52 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        valueType: 'Category',
        majorGridLines: {
            width: 0
        }
    },
    primaryYAxis: {
        lineStyle: {
            width: 0
        },
        majorTickLines: {
            width: 0
        }
    },
    series: [{
        dataSource: OrdersData,
        xName: 'Month', yName: 'Orders',
        type: 'Spline',
        marker: {
            visible: true
        },
        trendlines: [
            {
                type: 'Linear',
                width: 3,
                name: 'Trend',
                radialGradient: {
                    cx: 0.5, cy: 0.5, r: 0.5,
                    fx: 0.5, fy: 0.5,
                    gradientColorStop: [
                        { color: '#F97316', offset: 0, opacity: 1 },
                        { color: '#4F46E5', offset: 100, opacity: 1 }
                    ]
                }
            }
        ]
    }],
    legendSettings: {
        visible: true
    },
    title: 'Retail Orders Processed'
}, '#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/34.1.29/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>

Technical Indicators

Apply a radial gradient to a technical indicator by adding radialGradient inside the target Indicator.

var PriceSeries = [
    { Date: new Date(2025, 0, 1), Open: 103.9, High: 106.8, Low: 102.5, Close: 105.6, Volume: 182540000 },
    { Date: new Date(2025, 1, 1), Open: 105.2, High: 108.1, Low: 103.4, Close: 106.9, Volume: 176310000 },
    { Date: new Date(2025, 2, 1), Open: 106.7, High: 110.6, Low: 105.1, Close: 108.7, Volume: 189250000 },
    { Date: new Date(2025, 3, 1), Open: 108.9, High: 110.9, Low: 106.8, Close: 107.6, Volume: 171900000 },
    { Date: new Date(2025, 4, 1), Open: 107.8, High: 112.3, Low: 106.9, Close: 111.4, Volume: 196700000 },
    { Date: new Date(2025, 5, 1), Open: 111.2, High: 114.9, Low: 110.0, Close: 113.6, Volume: 205600000 },
    { Date: new Date(2025, 6, 1), Open: 113.5, High: 117.3, Low: 112.2, Close: 116.0, Volume: 213400000 },
    { Date: new Date(2025, 7, 1), Open: 116.1, High: 119.2, Low: 114.6, Close: 118.1, Volume: 221900000 },
    { Date: new Date(2025, 8, 1), Open: 117.9, High: 120.7, Low: 116.0, Close: 116.8, Volume: 198300000 },
    { Date: new Date(2025, 9, 1), Open: 116.7, High: 121.6, Low: 116.1, Close: 119.9, Volume: 234600000 },
    { Date: new Date(2025, 10, 1), Open: 120.2, High: 123.9, Low: 118.8, Close: 122.5, Volume: 226100000 }
];
var chart = new ej.charts.Chart({
    primaryXAxis: {
        title: 'Months',
        valueType: 'DateTime',
        intervalType: 'Months',
        labelFormat: 'MMM yyyy',
        edgeLabelPlacement: 'Shift',
        majorGridLines: {
            width: 0
        }
    },
    primaryYAxis: {
        title: 'Price (USD)',
        labelFormat: '${value}',
        minimum: 90, maximum: 130,
        interval: 10,
        lineStyle: {
            width: 0
        },
        majorTickLines: { width: 0 }
    },
    series: [{
        dataSource: PriceSeries, width: 2,
        xName: 'Date', yName: 'y', low: 'Low', high: 'High', close: 'Close', volume: 'Volume', open: 'Open',
        name: 'Equity Price',
        type: 'Candle'
    }],
    indicators: [{
        type: 'Ema', field: 'Close', seriesName: 'Equity Price', xName: 'Date', width: 2,
        period: 3,
        radialGradient: {
            cx: 0.5, cy: 0.5, r: 0.5,
            fx: 0.5, fy: 0.5,
            gradientColorStop: [
                { color: '#F97316', offset: 0, opacity: 1 },
                { color: '#4F46E5', offset: 100, opacity: 1 }
            ]
        }
    }],
    tooltip: {
        enable: true
    },
    legendSettings: {
        visible: false
    },
    title: 'Equity Price - Jan-Nov 2025'
}, '#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/34.1.29/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>