Articles in this section

How to add custom data marker in Blazor Chart?

In this article, we will discuss how to change the data marker’s appearance based on the Y plot.

Customizing data marker appearance using OnPointRender event

In Blazor Chart, the appearance of the data marker can be customized based on the Y value. Blazor Chart provides the OnPointRender event for customizing the properties before rendering each point.

The following properties are available in the PointRenderEventArgs:

  • Border: Specifies the color and 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.

Marker appearance can be customized based on the Y value by specifying the Shape, Border, and Fill properties of the PointRenderEventArgs.

The below code example illustrates the marker appearance based on the Y value. The border color changes to red and green by comparing it with the previous point of the series.

Index.Razor



@using Syncfusion.Blazor.Charts

<SfChart>
   
    <ChartEvents OnPointRender="@PointRender"></ChartEvents>
    
    <ChartSeriesCollection>
        <ChartSeries DataSource="@ConsumerReports" XName="X" YName="Y" Type="ChartSeriesType.Spline">
            <ChartMarker Visible="true" Height="10" Width="10" />
        </ChartSeries>
    </ChartSeriesCollection>
    
</SfChart>

@code {

    double temp = 0;

    public class ChartData
    {
        public double X { get; set; }
        public double Y { get; set; }
    }

    public List<ChartData> ConsumerReports = new List<ChartData>
    {
        new ChartData{ X= 2005, Y= 15 },
        new ChartData{ X= 2006, Y= 20 },
        new ChartData{ X= 2007, Y= 15 },
        new ChartData{ X= 2008, Y= 20 },
        new ChartData{ X= 2009, Y= 25 },
        new ChartData{ X= 2010, Y= 30 },
        new ChartData{ X= 2011, Y= 25 },
        new ChartData{ X= 2012, Y= 30 },
        new ChartData{ X= 2013, Y= 35 },
        new ChartData{ X= 2014, Y= 30 },
        new ChartData{ X= 2015, Y= 25 }
    };

    public void PointRender(PointRenderEventArgs args)
    {
        if (args.Point.YValue >= temp)
        {
            args.Border.Color = "green";
            temp = args.Point.YValue;
        }

        if (args.Point.YValue < temp)
        {
            args.Border.Color = "red";
            temp = args.Point.YValue;
        }        
    }
}

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

Output:

marker_appearence.png

View the sample in GitHub

Conclusion

I hope you enjoyed learning about customizing data marker appearance in the 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)
Access denied
Access denied