Numerical Axis Label Range

Good morning,

I'm using SfChart control to visualize some wave forms, but I have a problem with the "X numerical axis". The labels are correctly visualized until the values are bigger than 1E10-6 under this value labels value are all 0E00 as you can see in the attached images. I need at least to visualize values at 1E10-9 range.

Correct visualized labels
Incorrect visualized labels

1 Reply

MK Muneesh Kumar G Syncfusion Team October 12, 2018 12:33 PM UTC

Hi Daniel, 
 
Greetings from Syncfusion, we have analyzed your requirement and we would like to inform you that in our source we have rounded the label content with six digit for better visualization. So that the axis label displayed with zero value when the value under 0.000001  
 
However, we have resolved your problem by overriding GenerateVisibleLabels method in customized NumericalAxis as per the below code snippet.   
 
Code snippet [XAML]:  
     <chart:SfChart  Grid.Row="1" Margin="20"  
                       x:Name="chart" >  
             
            <chart:SfChart.PrimaryAxis>  
                <local:CustomNumericalAxis >                      
                </local:CustomNumericalAxis>  
            </chart:SfChart.PrimaryAxis>  
..  
  
        </chart:SfChart>  
  
Code snippet [C#]:  
public class CustomNumericalAxis :NumericalAxis  
    {  
        protected override void GenerateVisibleLabels()  
        {  
            DoubleRange range = VisibleRange;  
            double interval = (double)this.GetType().GetProperty("VisibleInterval", System.Reflection.BindingFlags.NonPublic |  
                System.Reflection.BindingFlags.Instance).GetValue(this);  
             
            double position = range.Start;  
  
            double previousPosition = double.NaN;  
  
            for (; position <= range.End; position += interval)  
            {  
                if (position == previousPosition)  
                    break;  
  
                if (range.Inside(position))  
                {  
                    VisibleLabels.Add(new ChartAxisLabel(position, GetActualLabelContent(position), position));  
                }  
  
                if (SmallTicksPerInterval>0)  
                {  
                    AddSmallTicksPoint(position);  
                }  
  
                previousPosition = position;  
            }  
  
            if (((Maximum != null && range.End.Equals(Maximum))  
                || EdgeLabelsVisibilityMode == EdgeLabelsVisibilityMode.AlwaysVisible  
                || (EdgeLabelsVisibilityMode == EdgeLabelsVisibilityMode.Visible && ZoomFactor==0))  
                && !range.End.Equals(position - interval))  
            {  
                VisibleLabels.Add(new ChartAxisLabel(range.End, GetActualLabelContent(range.End), range.End));  
            }  
        }  
  
        internal object GetActualLabelContent(double position)  
        {  
            return position.ToString(this.LabelFormat, CultureInfo.CurrentCulture);  
        }  
    }  
  
We have prepared a sample based on this, please find the sample from the following location.   
  
  
Output:   
   
  
Also, if you like to customize the generated axis label content, you can achieve this by using below solutions.  
  
Solution 1: You can achieve this by customizing LabelContent in LabelCreated event in axis as per the below code snippet.  
  
Code snippet [C#]:  
private void CustomNumericalAxis_LabelCreated(object sender, LabelCreatedEventArgs e)  
        {  
            e.AxisLabel.LabelContent = e.AxisLabel.LabelContent;  
        }  
  
Code snippet [XAML]:  
           <chart:SfChart.PrimaryAxis>  
                <local:CustomNumericalAxis     
                    LabelCreated="CustomNumericalAxis_LabelCreated">                      
                </local:CustomNumericalAxis>  
            </chart:SfChart.PrimaryAxis>  
  
Solution 2: By using LabelFormat property in axis, you can customize the axis label content as per the below code snippet.  
  
Code snippet [XAML]:  
           <chart:SfChart.PrimaryAxis>  
                <local:CustomNumericalAxis LabelFormat="#.##E+0">                      
                </local:CustomNumericalAxis>  
            </chart:SfChart.PrimaryAxis>  
  
Hope this helps.  
  
Thanks,
Muneesh Kumar G.
 
 
 
 


Loader.
Up arrow icon