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. Image for the cookie policy date

Custom Label

Hello,


I am using Sfchart, and on numerical axis (vertical one)  I want to add specific labels and the other one I want to hide. For example on the y axis I just want to have 3 labels specify by me. I can't find any solution for that.  
So how should I do that? 

Thank you.

5 Replies

PS Parthiban Sundaram Syncfusion Team September 25, 2017 10:53 AM UTC

Hi Alex,  
  
Thanks for using Syncfusion products.  
  
You can achieve this requirement using LabelCreated event of NumericalAxis. Please refer the following code snippet for more details.  
  
Code snippet:  
  
  
           private void YAxis_LabelCreated(object sender, ChartAxis.LabelCreatedEventArgs e)  
        {  
            // Specify the label to show  
            if (e.AxisLabel.Position != 20 && e.AxisLabel.Position != 80 && e.AxisLabel.Position != 150)   
                e.AxisLabel.IsVisible = false;  
        }  
  
  
We have created a simple demo sample to demonstrate this. Please download it from below location.    
  
  
Please let us know, if you need further assistance on this.  
  
Regards,  
Parthiban S   



AL Alex September 26, 2017 07:21 AM UTC

Thank you for your answer.

Another thing that I want to do is to add a label to specific position, where I have no data.



PS Parthiban Sundaram Syncfusion Team September 27, 2017 08:33 PM UTC

Hi Alex, 
  
 
Thanks for the update. 
 
We have achieved your requirement by extending NumericalAxis and overriding GenerateVisibleLabels method to add the labels in specified position. Please refer the NumericalAxisExt files for more details. 
 
Code snippet: 
  
        protected override void GenerateVisibleLabels() 
        { 
            base.GenerateVisibleLabels(); 
            VisibleLabels.Clear(); 
            for (double i = VisibleRange.Start; i < VisibleRange.End; i++) 
            { 
                if(i == 20 || i == 40 || i == 60) // specify the label you need 
                    VisibleLabels.Add(new ChartAxisLabel(i, i.ToString())); 
            } 
        } 
 
 
Please download the sample from following location. 
 
 
Please let us know, if you need further assistance. 
 
Regards, 
Parthiban S 



AL Alex September 28, 2017 08:52 AM UTC

Hi Parthiban,

Thanks a lot for the solution! That helped a lot.

Best regards,

Alex



PS Parthiban Sundaram Syncfusion Team September 29, 2017 04:30 AM UTC

Hi Alex,

Thanks for the update. We are glad that the given solution has helped to achieve your requirement. Please let us know, if you need further assistance on this.

Regards,
Parthiban S


Loader.
Up arrow icon