Gradient in Angular Chart component
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { CategoryService, ColumnSeriesService, DataLabelService, LegendService, TooltipService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
import { SalesData } from './datasource';
@Component({
imports: [
ChartModule
],
providers: [CategoryService, ColumnSeriesService, DataLabelService, LegendService, TooltipService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis" [title]="title" [tooltip]="tooltip" [legendSettings]="legendSettings">
<e-series-collection>
<e-series [dataSource]="salesData" type="Column" xName="Month" yName="Amount" name="Sales" [marker]="marker" [linearGradient]="linearGradient"></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public salesData?: Object[];
public marker?: Object;
public linearGradient?: Object;
public tooltip?: Object;
public legendSettings?: Object;
public title?: string;
ngOnInit(): void {
this.salesData = SalesData;
this.primaryXAxis = { valueType: 'Category' };
this.primaryYAxis = { labelFormat: '${value}k' };
this.marker = { visible: true, isFilled: true };
this.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 }
]
};
this.tooltip = { enable: true };
this.legendSettings = { visible: true };
this.title = 'Monthly Sales Performance';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Trendlines
Apply a linear gradient to a trendline by adding linearGradient inside the target Trendline.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { CategoryService, LineSeriesService, TrendlinesService, SplineSeriesService, LegendService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
import { OrdersData } from './datasource';
@Component({
imports: [ChartModule],
providers: [CategoryService, LineSeriesService, SplineSeriesService, LegendService,TrendlinesService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis" [title]="title" [legendSettings]="legendSettings">
<e-series-collection>
<e-series [dataSource]="ordersData" type="Spline" xName="Month" name="Orders" yName="Orders" [marker]="marker">
<e-trendlines>
<e-trendline type="Linear" width="3" name="Trend" [linearGradient]="trendlineGradient"></e-trendline>
</e-trendlines>
</e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public ordersData?: Object[];
public marker?: Object;
public trendlineGradient?: Object;
public legendSettings?: Object;
public title?: string;
ngOnInit(): void {
this.ordersData = OrdersData;
this.primaryXAxis = {
valueType: 'Category',
majorGridLines: { width: 0 }
};
this.primaryYAxis = {
lineStyle: { width: 0 },
majorTickLines: { width: 0 }
};
this.marker = { visible: true };
this.trendlineGradient = {
x1: 0, y1: 0,
x2: 1, y2: 0,
gradientColorStop: [
{ color: '#F97316', offset: 0, opacity: 1 },
{ color: '#4F46E5', offset: 100, opacity: 1 }
]
};
this.legendSettings = { visible: true };
this.title = 'Retail Orders Processed';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Technical Indicators
Apply a linear gradient to a technical indicator by adding linearGradient inside the target Indicator.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CandleSeriesService, LineSeriesService, EmaIndicatorService, TooltipService, LegendService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
import { PriceSeries } from './datasource';
@Component({
imports: [ChartModule],
providers: [DateTimeService, CandleSeriesService, LineSeriesService, EmaIndicatorService, TooltipService, LegendService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis" [title]="title" [tooltip]="tooltip" [legendSettings]="legendSettings" [indicators]="indicators">
<e-series-collection>
<e-series [dataSource]="priceData" type="Candle" xName="Date" yName="y" low="Low" high="High" close="Close" open="Open" volume="Volume" name="Equity Price" [width]="2"></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public priceData?: Object[];
public indicatorGradient?: Object;
public tooltip?: Object;
public legendSettings?: Object;
public title?: string;
public indicators?: Object;
ngOnInit(): void {
this.priceData = PriceSeries;
this.primaryXAxis = {
title: 'Months',
valueType: 'DateTime',
intervalType: 'Months',
labelFormat: 'MMM yyyy',
edgeLabelPlacement: 'Shift',
majorGridLines: { width: 0 }
};
this.primaryYAxis = {
title: 'Price (USD)',
labelFormat: '${value}',
minimum: 90, maximum: 130,
interval: 10,
lineStyle: { width: 0 },
majorTickLines: { width: 0 }
};
this.indicatorGradient = {
x1: 0, y1: 0,
x2: 1, y2: 0,
gradientColorStop: [
{ color: '#7C3AED', offset: 0, opacity: 1 },
{ color: '#F59E0B', offset: 100, opacity: 1 }
]
};
this.indicators=[
{
type: "Ema",
field: "Close",
seriesName: "Equity Price",
xName: "Date",
period: 3,
linearGradient: this.indicatorGradient,
width: 2
}
]
this.tooltip = { enable: true };
this.legendSettings = { visible: false };
this.title = 'Equity Price - Jan-Nov 2025';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { CategoryService, ColumnSeriesService, DataLabelService, LegendService, TooltipService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
import { SalesData } from './datasource';
@Component({
imports: [ChartModule],
providers: [CategoryService, ColumnSeriesService, DataLabelService, LegendService, TooltipService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis" [title]="title" [tooltip]="tooltip" [legendSettings]="legendSettings">
<e-series-collection>
<e-series [dataSource]="salesData" type="Column" xName="Month" yName="Amount" name="Sales" [marker]="marker" [radialGradient]="radialGradient"></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public salesData?: Object[];
public marker?: Object;
public radialGradient?: Object;
public tooltip?: Object;
public legendSettings?: Object;
public title?: string;
ngOnInit(): void {
this.salesData = SalesData;
this.primaryXAxis = { valueType: 'Category' };
this.primaryYAxis = { labelFormat: '${value}k' };
this.marker = { visible: true, isFilled: true, dataLabel: { visible: true } };
this.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 }
]
};
this.tooltip = { enable: true };
this.legendSettings = { visible: true };
this.title = 'Monthly Sales Performance';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Trendlines
Apply a linear gradient to a trendline by adding linearGradient inside the target Trendline.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { CategoryService, LineSeriesService, TrendlinesService, SplineSeriesService, LegendService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
import { OrdersData } from './datasource';
@Component({
imports: [ChartModule],
providers: [CategoryService, LineSeriesService, SplineSeriesService, LegendService,TrendlinesService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis" [title]="title" [legendSettings]="legendSettings">
<e-series-collection>
<e-series [dataSource]="ordersData" type="Spline" xName="Month" name="Orders" yName="Orders" [marker]="marker">
<e-trendlines>
<e-trendline type="Linear" width="3" name="Trend" [radialGradient]="radialGradient"></e-trendline>
</e-trendlines>
</e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public ordersData?: Object[];
public marker?: Object;
public radialGradient?: Object;
public legendSettings?: Object;
public title?: string;
ngOnInit(): void {
this.ordersData = OrdersData;
this.primaryXAxis = {
valueType: 'Category',
majorGridLines: { width: 0 }
};
this.primaryYAxis = {
lineStyle: { width: 0 },
majorTickLines: { width: 0 }
};
this.marker = { visible: true };
this.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 }
]
};
this.legendSettings = { visible: true };
this.title = 'Retail Orders Processed';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Technical Indicators
Apply a linear gradient to a technical indicator by adding linearGradient inside the target Indicator.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { ChartModule } from '@syncfusion/ej2-angular-charts'
import { DateTimeService, CandleSeriesService, LineSeriesService, EmaIndicatorService, TooltipService, LegendService } from '@syncfusion/ej2-angular-charts';
import { Component, OnInit } from '@angular/core';
import { PriceSeries } from './datasource';
@Component({
imports: [ChartModule],
providers: [DateTimeService, CandleSeriesService, LineSeriesService, EmaIndicatorService, TooltipService, LegendService],
standalone: true,
selector: 'app-container',
template: `<ejs-chart id="chart-container" [primaryXAxis]="primaryXAxis" [primaryYAxis]="primaryYAxis" [title]="title" [tooltip]="tooltip" [legendSettings]="legendSettings" [indicators]="indicators">
<e-series-collection>
<e-series [dataSource]="priceData" type="Candle" xName="Date" yName="y" low="Low" high="High" close="Close" open="Open" volume="Volume" name="Equity Price" [width]="2"></e-series>
</e-series-collection>
</ejs-chart>`
})
export class AppComponent implements OnInit {
public primaryXAxis?: Object;
public primaryYAxis?: Object;
public priceData?: Object[];
public radialGradient?: Object;
public tooltip?: Object;
public legendSettings?: Object;
public title?: string;
public indicators?: Object;
ngOnInit(): void {
this.priceData = PriceSeries;
this.primaryXAxis = {
title: 'Months',
valueType: 'DateTime',
intervalType: 'Months',
labelFormat: 'MMM yyyy',
edgeLabelPlacement: 'Shift',
majorGridLines: { width: 0 }
};
this.primaryYAxis = {
title: 'Price (USD)',
labelFormat: '${value}',
minimum: 90, maximum: 130,
interval: 10,
lineStyle: { width: 0 },
majorTickLines: { width: 0 }
};
this.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 }
]
};
this.indicators=[
{
type: "Ema",
field: "Close",
seriesName: "Equity Price",
xName: "Date",
period: 3,
radialGradient: this.radialGradient,
width: 2
}
]
this.tooltip = { enable: true };
this.legendSettings = { visible: false };
this.title = 'Equity Price - Jan-Nov 2025';
}
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));