Articles in this section
Category / Section

How to set the gradient color for the Angular Column Charts by using pointColorMapping?

3 mins read

Description

This article shows how to set the gradient color for Angular Column Charts by using pointColorMapping.

Solution

A gradient color is a visual representation of the range of colors arranged in a smooth transition from one color to another. This gradient color is filled in the specific column by using the pointColorMapping property in the series of the chart.

To achieve this, you can create a linear-gradient SVG and assign an ID to it. Then, you can map the field that contains the ID of the gradient to the pointColorMapping property in the series. This way, you can create a custom gradient color for your chart.

Code Snippet

app.component.html

<ejs-chart>
 <e-series-collection>
   <e-series [pointColorMapping]="pointColorMapping"></e-series>
 </e-series-collection>
</ejs-chart>
<svg style="height:0">
 <defs>
   <linearGradient id="gradient-chart1" x1="0" x2="0" y1="0" y2="1">
     <stop offset="0" />
     <stop offset="1" />
   </linearGradient>
   <linearGradient id="gradient-chart2" x1="0" x2="0" y1="0" y2="1">
     <stop offset="0" />
     <stop offset="1" />
   </linearGradient>
   <linearGradient id="gradient-chart3" x1="0" x2="0" y1="0" y2="1">
     <stop offset="0" />
     <stop offset="1" />
   </linearGradient>
 </defs>
</svg>
<style>
     #gradient-chart1 stop {
           stop-color: green;
     }
     #gradient-chart1 stop[offset="0"] {
           stop-opacity: 0.75;
     }
     #gradient-chart1 stop[offset="1"] {
           stop-opacity: 0;
     }
     #gradient-chart2 stop {
           stop-color: orange;
     }
     #gradient-chart2 stop[offset="0"] {
           stop-opacity: 0.75;
     }
     #gradient-chart2 stop[offset="1"] {
           stop-opacity: 0;
     }
     #gradient-chart3 stop {
           stop-color: pink;
     }
     #gradient-chart3 stop[offset="0"] {
           stop-opacity: 0.75;
     }
     #gradient-chart3 stop[offset="1"] {
           stop-opacity: 0;
     }
</style>

app.component.ts

   this.data = [
     { x: 'BGD', y: 150, text: 'Bangaladesh', color: 'red' },
     { x: 'BTN', y: 103, text: 'Bhutn', color: 'blue' },
     { x: 'NPL', y: 198, text: 'Nepal', color: "url(#gradient-chart1)" },
     { x: 'THA', y: 189, text: 'Thiland', color: 'url(#gradient-chart2)' },
     { x: 'MYS', y: 250, text: 'Malaysia', color: 'url(#gradient-chart3)' },
   ];
   this.pointColorMapping = 'color';

The following image illustrates the output of the above code.

image.png

View Sample in Stackblitz

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied