We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set the custom labels with auto range for axis?

Description:

This article describes how to set the custom labels for the axis when we do not specify the range explicitly, i.e., without specifying minimum and maximum values.

Solution:

This requirement can be achieved by adding custom labels based on the position of visible labels in ActualRangeChanged event.

XAML

 

 <!--Hooked ActualRangeChangedEvent-->

<chart:SfChart.SecondaryAxis>

<chart:NumericalAxis ActualRangeChanged="NumericalAxis_ActualRangeChanged"/>                         

 </chart:SfChart.SecondaryAxis>

 

 

C#

private void NumericalAxis_ActualRangeChanged(object sender, Syncfusion.UI.Xaml.Charts.ActualRangeChangedEventArgs e)

{

            var axis = sender as NumericalAxis;

 

            //Gets the collection of visible labels.

            var labels = axis.VisibleLabels;

 

            if (labels != null)

            {

                if (axis.CustomLabels.Count > 0)

                    axis.CustomLabels.Clear();

 

                //To add the custom labels based on the position of visible labels.

                for (int index = 0; index < labels.Count; index++)

                {

                    var axisLabel = new ChartAxisLabel()

                    {

                        Position = labels[index].Position,//To set the position where the custom label should be placed.

 

                        LabelContent = "Item" + index//To set the content from which labels are to be taken.

                    };

 

                    axis.CustomLabels.Add(axisLabel);

                }

            }

        }

 

 

Output

The following screenshot illustrates the custom labels based on the range in y-axis.

 

Article ID: Published Date: Last Revised Date: Platform: Control:
5907 12/23/2015 03/09/2018 WPF SfChart
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon