MVVM SfChart binding Primary and Secondary Axes

I'd like to be able to bind the axes as they could be numerical or datetime (not known till runtime).
If this is my xaml
        <syncfusion:SfChart Grid.Row="1"
                            Annotations="{Binding Path=chartAnnotation}"
                            Series="{Binding CSeries}"
                            PrimaryAxis="{Binding PAxis}"
                            SecondaryAxis="{Binding SAxis}"
                            Legend="{Binding CLegend}">

         <syncfusion:SfChart.Behaviors>
            <syncfusion:ChartZoomPanBehavior EnableMouseWheelZooming="True" ZoomRelativeToCursor="True">
            </syncfusion:ChartZoomPanBehavior>
         </syncfusion:SfChart.Behaviors>
      </syncfusion:SfChart>

In my viewmodel constructor i intialize the following:

         DateTimeAxis dta = new DateTimeAxis();
         dta.LabelRotationAngle = 45;
         dta.Header = "Name";
         PAxis = dta;

         NumericalAxis na = new NumericalAxis();
         na.Header = "Value";
         na.Interval = 100;
         SAxis = na;

CLegend = new ChartLegend()
         {
            ToggleSeriesVisibility = true,
            CheckBoxVisibility = Visibility.Visible
         };

         //Adding Annotations.
         chartAnnotation = new AnnotationCollection();
         VerticalLineAnnotation verticalLineAnnotation = new VerticalLineAnnotation();
         verticalLineAnnotation.ShowAxisLabel = true;
         verticalLineAnnotation.CoordinateUnit = CoordinateUnit.Axis;
         verticalLineAnnotation.X1 = new DateTime(2011, 09, 19, 18, 0, 0).ToOADate();
         chartAnnotation.Add(verticalLineAnnotation);

The legend and the annotation are visible, but the primary and secondary axes have the default appearance.
Are the axes even bindable? 

5 Replies 1 reply marked as answer

SJ Suyamburaja Jayakumar Syncfusion Team November 7, 2020 04:14 AM UTC

Hi Zeljko Lazic, 
  
Greetings from Syncfusion.   
  
We need some more information for Query, you can use the binding the axis property more than 1 time in chart. If you are binding the same property again chart won’t consider that axis values render the default axis. If you want additional axis, you have to add that to the XAxis or YAxis property in series.  
  
More information please refer the UG link, 
  
If we misunderstood your query, please share more details regarding your exact requirements in detail.  
  
Regards, 
Suyamburaja J. 
 



ZL Zeljko Lazic December 3, 2020 07:00 PM UTC

Hi,
See the attached example project (it's a visual studio 2015 project using 18.2.0.44 of syncfusion).
I just have a primary and secondary axis
<syncfusion:SfChart Header="{Binding ChartName}"
   Series="{Binding CSeries}"
                    PrimaryAxis="{Binding PAxis}"
                    SecondaryAxis="{Binding SAxis}">
      
   </syncfusion:SfChart>
Here's the initialization of the axes in the ShellViewModel constructor
DateTimeAxis primaryAxis = new DateTimeAxis();
primaryAxis.Header = "Time";
primaryAxis.LabelRotationAngle = 90;
PAxis = primaryAxis;
 
NumericalAxis secondaryAxis = new NumericalAxis();
secondaryAxis.Header = "Height";
secondaryAxis.FontSize = 3;
SAxis = secondaryAxis;

Here's a screenshot of the resulting chart:

The headers are not shown, the rotation angle and font size are not applied.



Attachment: LineSeriesInListBoxWPF_218aa98.zip


SJ Suyamburaja Jayakumar Syncfusion Team December 4, 2020 01:04 PM UTC

Hi Zeljko Lazic, 
 
Thanks for the update. 
 
Currently we have validate the query and we will update the complete details on or before December 8, 2020. 
 
Regards,  
Suyamburaja J. 



SJ Suyamburaja Jayakumar Syncfusion Team December 8, 2020 05:23 PM UTC

Hi Zeljko Lazic,  
  
Sorry for the delay. 
  
We were able to reproduce the reported issue at our end. Primary and secondary axis binding is not working in Prism architecture alone. For Series XAxis and YAxis binding is working fine. So we are analyzing the root cause of the issue. We will update the complete details on or before December 10, 2020.  
  
Regards,   
Suyamburaja J. 



SJ Suyamburaja Jayakumar Syncfusion Team December 10, 2020 02:19 PM UTC

Hi Zeljko Lazic, 
 
Thanks for your patience.  
   
We would let you know that it has been resolved by setting the twoway binding of Primary and secondary axis as per in below code snippet, 
 
XAML: 
<syncfusion:SfChart x:Name="chart"  
                                Header="{Binding ChartName}"  
                                PrimaryAxis="{Binding PAxis, Mode=TwoWay}" 
                                SecondaryAxis="{Binding SAxis, Mode=TwoWay}" 
                                Series="{Binding CSeries}"> 
            </syncfusion:SfChart> 
 
Please let us know if you need any further assistance. 
 
Regards, 
Suyamburaja J. 


Marked as answer
Loader.
Up arrow icon