How to change Axis Header dynamically?

I have an app that plots various things based on the selected item in a combo box. I would like to be able to change the headers of the individual axes when a new item is selected. How can I do that? I've tried:

        private void ParameterChoice(object sender, RoutedEventArgs e)
        {
            if (ParameterSelectionConboBox.SelectedIndex == 0)
            {
                // Calibrating for Parameter 1
                regXheader = "Parameter X1";
                regYheader = "Parameter Y1";
            }
            else
            {
                // Calibrating for Parameter 2
                regXheader = "Parameter X2";
                regYheader = "Parameter Y2";
            }
        }

and the XAML:

<syncfusion:SfChart x:Name="ParameterChart" Header="Parameter vs Extinction" Width="600" Margin="0,20,0,0" HorizontalAlignment="Center" VerticalAlignment="Top">
                <syncfusion:SfChart.PrimaryAxis>
                    <syncfusion:NumericalAxis x:Name="RegressionXAxis" Header="{Binding regXheader}"/>
                </syncfusion:SfChart.PrimaryAxis>
                <syncfusion:SfChart.SecondaryAxis>
                    <syncfusion:NumericalAxis x:Name="RegressionYAxis" Header="{Binding regYheader}"/>
                </syncfusion:SfChart.SecondaryAxis>
                <syncfusion:ScatterSeries x:Name="series"
                                          EnableAnimation="True"
                                          AnimationDuration="00:00:02"
                                          Palette="BlueChrome"
                                          Stroke="Black" StrokeThickness="1"
                                          ScatterHeight="8" ScatterWidth="8"
                                          ListenPropertyChange="True"
                                          SegmentSelectionBrush="Green"
                                          YBindingPath="X"
                                          XBindingPath="Y"/>
            </syncfusion:SfChart>

1 Reply

MK Muneesh Kumar G Syncfusion Team August 14, 2018 09:04 AM UTC

Hi Ben, 
 
Greetings from Syncfusion, we have analyzed your requirement and you can achieve this by setting DataContext for MainPage and implementing INotifyPropertyChanged for binding properties as per the below code snippet.  
 
Code snippet [C#]: 
public sealed partial class MainPage : Page, INotifyPropertyChanged 
    { 
        public MainPage() 
        { 
            this.InitializeComponent(); 
 
            ... 
            DataContext = this; 
        } 
 
 
        private void ParameterSelectionConboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
       { 
            if (ParameterSelectionConboBox.SelectedIndex == 0) 
            { 
                // Calibrating for Parameter 1 
                regXheader = "Parameter X1"; 
                regYheader = "Parameter Y1"; 
            } 
            else 
            { 
                // Calibrating for Parameter 2 
                regXheader = "Parameter X2"; 
                regYheader = "Parameter Y2"; 
            } 
        } 
 
        
        private string xHeader; 
 
        public string regXheader 
        { 
            get { return xHeader; } 
            set { xHeader = value; OnPropertyChanged("regXheader"); } 
        } 
 
 
        private string yHeader; 
 
        public string regYheader 
        { 
            get { return yHeader; } 
            set { yHeader = value; OnPropertyChanged("regYheader"); } 
        } 
 
        public event PropertyChangedEventHandler PropertyChanged; 
 
        protected void OnPropertyChanged(string name) 
        { 
            PropertyChangedEventHandler handler = PropertyChanged; 
            if (handler != null) 
            { 
                handler(this, new PropertyChangedEventArgs(name)); 
            } 
        } 
    } 
 
We have prepared a sample based on this, please find the sample from the following location. 
 
 
Hope this helps.  
 
Thanks, 
Muneesh Kumar G. 
 


Loader.
Up arrow icon