Articles in this section
Category / Section

How to customize the segment color based on the Y value in Blazor Chart?

3 mins read

This article explains how to set different color to its segment based on its Y value in the Blazor Chart.

Customizing segment color based on Y value in Blazor Chart Component

This can be achieved by using OnPointRender event. This event triggers before each point for the series is rendered.

The following properties are available in the PointRenderEventArgs.

Border – Specifies the color and the width of the point border.

Fill – Specifies the fill color of the point.

Height – Specifies the current point’s height.

Shape – Specifies the marker shape of the point.

Width – Specifies the current point’s width.

We can customize the Segment color of a chart series based on its Y value by specifying the Fill property of the PointRenderEventArgs.

The following code example illustrates this.

Index.razor


@using Syncfusion.Blazor.Charts

<SfChart>  
   
    <ChartEvents OnPointRender="PointRender"></ChartEvents>
    
    <ChartSeriesCollection>
        <ChartSeries DataSource="@Data" XName="XValue" YName="YValue" Type="ChartSeriesType.Column" />
    </ChartSeriesCollection>
    
</SfChart>

@code {

    public class ChartData
    {
        public double XValue { get; set; }
        public double YValue { get; set; }
    }
    
    public List<ChartData> Data = new List<ChartData>
    {
        new ChartData { XValue = 10, YValue = 10 },
        new ChartData { XValue = 20, YValue = 25 },
        new ChartData { XValue = 30, YValue = 30 },
        new ChartData { XValue = 40, YValue = 10 },
        new ChartData { XValue = 50, YValue = 30 },
        new ChartData { XValue = 60, YValue = 25 },
        new ChartData { XValue = 70, YValue = 50 },
    };
    
    public void PointRender(PointRenderEventArgs args)
    {
        if(args.Point.YValue <= 20)
        {
            args.Fill = "red";
        }
        if (args.Point.YValue > 20 && args.Point.YValue <= 40)
        {
            args.Fill = "blue";
        }
        if(args.Point.YValue > 40)
        {
            args.Fill = "green";
        }
    }
}

The following screenshot illustrates the output of the above code snippet.

Output:

Segment_Color.png

View the Sample in GitHub

Conclusion

I hope you enjoyed learning how to customize the segment color based on Y value of Blazor Chart Component.

You can refer to our Blazor 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 Blazor 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, support portal, 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