Always Display 0 on YAxis for FastLineSeries

Hi,

I have an SfChart control with three shared FastLineSeries inside of it. They all share a single Primary Axis, but each have their own YAxis. The Numerical YAxis scales automatically, but I want the 0 point to always be visible. In specific instances, the 0 label will go away when the axis auto-scales. Is there a way to ensure that the "0" label is always visible? I can't use "StartRangeFromZero" because I also show negative values. I tried to listen to the ActualRangedChanged event, but it doesn't seem to provide me with what I need.

Thanks!

5 Replies

SJ Suyamburaja Jayakumar Syncfusion Team February 19, 2020 12:12 PM UTC

Hi Sean Schellinger, 
 
Greetings from Syncfusion. 
 
Query: Always Display 0 on YAxis for FastLineSeries 
 
 
We would like to let you know that your requirement has been achieved by the SfChart RangeChanged Event. Please refer the below code snippet 
 
CodeSnippet[XAML]: 
<syncfusion:SfChart x:Name="chart"  Header="Chart" Height="300" Width="500"> 
 
            <syncfusion:SfChart.PrimaryAxis> 
                <syncfusion:CategoryAxis  Header="Name" FontSize="14"/> 
            </syncfusion:SfChart.PrimaryAxis> 
 
            <syncfusion:SfChart.SecondaryAxis> 
                <syncfusion:NumericalAxis x:Name="numericalAxis" ActualRangeChanged="NumericalAxis_ActualRangeChanged"> 
                </syncfusion:NumericalAxis> 
            </syncfusion:SfChart.SecondaryAxis> 
 
            <syncfusion:LineSeries ItemsSource="{Binding Data}" XBindingPath="Name" YBindingPath="Height"/> 
 
        </syncfusion:SfChart> 
 
 
C#: 
private void NumericalAxis_ActualRangeChanged(object sender, ActualRangeChangedEventArgs e) 
        {   
            // you can add the custom label at the 0th position when your data ranges from negative to positive values 
            if((double)e.ActualMinimum <= 0) 
            { 
                numericalAxis.CustomLabels.Add(new ChartAxisLabel() { Position = 0, LabelContent = "0" }); 
            } 
            // you can set the ActualMininum when your data ranges above 0. 
            else 
            { 
                e.ActualMinimum = 0; 
            } 
        } 
 
 
Please let us know if you need any further assistance.   
 
Regards, 
Suyamburaja J. 
 



SS Sean Schellinger February 19, 2020 02:54 PM UTC

Hi,

I tried this solution, but it did not work. I can see the list of CustomLabels with a long list of labels at 0, but they do not appear on the axis. I've attached my code.

Attachment: SampleCode_ac4f02e7.zip


SJ Suyamburaja Jayakumar Syncfusion Team February 20, 2020 02:42 PM UTC

Hi Sean Schellinger,  
 
We checked the code snippet provided and did not have any Chart reference to exclude the code snippet below.   
 
  
  
With this does not contain much more information on how to proceed further. We suspected that you might be wrongly attach the files. So, could you please update us with a chart-related code snippet or, if possible, provide a reproducing sample to check it further and provide a possible solution.  
 
Regards, 
Suyamburaja J 
  



SS Sean Schellinger February 21, 2020 07:58 PM UTC

The attached code wasn't meant to be a fully functional sample. Unfortunately, in order to provide that you would need me to provide multiple projects. I would rather not do this. My intention in providing the code was to show you what I tried and that it does not work. I set up an SfChart with 3 embedded charts as you can see in VentMon.xaml. Then, inside of VentMon.xaml.cs, you can see I subscribe to the ActualChangeRangeChanged event for each YAxis. I then added a custom label as you described as the solution. I used a breakpoint to ensure the labels were being added the the object (they were), but the label was NOT visible on the charts. 

It is difficult to provide a working sample due to the many dependencies needed. Are there other potential solutions you can provide?


LA Lavanya Anaimuthu Syncfusion Team February 24, 2020 12:52 PM UTC

Hi Sean Schellinger, 
 
Thanks for your update.  
  
Under your account, we have created a support incident to track the status of this reported issue  
  
Please log on to our support website to check for further updates.  
  
 
Thanks, 
Lavanya A. 


Loader.
Up arrow icon