How to Set the Color for the Angular Charts by PointColorMapping?
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.
Conclusion
We hope you enjoyed learning about ow to set the gradient color for Angular Column Charts by using pointColorMapping
You can refer to our Angular Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular Chart example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!