Articles in this section
Category / Section

How to set the gradient color for the JavaScript Area Chart?

2 mins read

Description

This article explains how to set the gradient color for the JavaScript Area Chart.

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 chart by using the fill property in the series of a chart. You can create a linear-gradient SVG and then set its ID to the fill property in the series.

Code Snippet

The following code shows how to add the gradient color to the series.

index.html

<svg>
<defs>
   <linearGradient id="grad1" x1="100%" y1="0%" x2="0%" y2="100%">
   <stop offset="0%" style="stop-color: #85e6b9;stop-opacity:1" />
   <stop offset="100%" style="stop-color:#d8f7e8;stop-opacity:0.5" />
   </linearGradient>
</defs>
</svg>

index.ts

series: [
 {
     dataSource: [
        { x: "Mon", y: 0.5 }, { x: "Tue", y: 1 },
        { x: "Wed", y: 2 }, { x: "Thur", y: 1.2 },
        { x: "Fri", y: 2.3 }, { x: "Sat", y: 0.5 },
        { x: "Sun", y: 1 }
     ],
     fill: "url('#grad1')",
     xName: 'x', yName: 'y', type: 'SplineArea',
     border: { color: "transparent" },
          opacity: 1
   }
]

The following image illustrates the output of the above code.

image.png

Refer to the working sample for additional details and implementation: View Sample in Stackblitz

Conclusion

We hope you enjoyed learning how to set the gradient color for the JavaScript Area Chart.

You can refer to our JavaScript Charts feature tour page to learn about its other features and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Charts example to understand how to create and visualize 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 comment section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!

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