Question About Changing Axis Line Color in SfCartesianChart

Hi Syncfusion Team,


Thank you for your excellent work on Syncfusion components.


I am currently working with SfCartesianChart and trying to change the color of the Axis line using DynamicResource, but I haven’t had any success so far. Could you provide some guidance on how to achieve this?


Any help would be greatly appreciated.


Best regards,




Attachment: AxisLineTest_9782aa83.zip

4 Replies

AJ Arul Jenith Berkmans Syncfusion Team March 4, 2025 02:32 PM UTC

Hi Jon Kao,


Currently, the DynamicResource for axis line color is not supported. We are checking the possibilities for a workaround. We need additional time and will provide a detailed update within one business day (March 5, 2025).


Best regards, 

Arul Jenith B.



AJ Arul Jenith Berkmans Syncfusion Team March 5, 2025 10:36 AM UTC

Hi Jon Kao,

 

As a workaround, we recommend using data binding with a ViewModel. This involves binding a color property in your ViewModel to the axis line style in XAML and updating this property in your event handler—ensuring dynamic updates in the UI.

 

Here is a simple code snippet:

 

XAML:

 

 <chart:SfCartesianChart.XAxes>

     <chart:CategoryAxis>

         <chart:CategoryAxis.AxisLineStyle>

             <chart:ChartLineStyle

                 StrokeWidth="2"

                 Stroke="{Binding AxisColor}"/>

         </chart:CategoryAxis.AxisLineStyle>

 

         <chart:CategoryAxis.LabelStyle>

<chart:ChartAxisLabelStyle

TextColor="{Binding AxisColor}"

FontSize="12"/>

</chart:CategoryAxis.LabelStyle>

     </chart:CategoryAxis>

 </chart:SfCartesianChart.XAxes>

 

 <chart:SfCartesianChart.YAxes>

     <chart:NumericalAxis>

         <chart:NumericalAxis.AxisLineStyle>

             <chart:ChartLineStyle

                 StrokeWidth="2"

                 Stroke="{Binding AxisColor}"/>

         </chart:NumericalAxis.AxisLineStyle>

     </chart:NumericalAxis>

 </chart:SfCartesianChart.YAxes> 

 

ViewModel:

 

public class ViewModel : INotifyPropertyChanged

{

    private Color? _axisColor;

 

    public Color? AxisColor

    {

        get => _axisColor;

        set

        {

            if (_axisColor != value)

            {

                _axisColor = value;

                OnPropertyChanged();

            }

        }

    }

 

 

public ViewModel()

{

        AxisColor = Colors.Blue;

}

 

 

    public event PropertyChangedEventHandler? PropertyChanged;

 

    protected void OnPropertyChanged([CallerMemberName] string propertyName = null)

    {

        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    }

}

 

Button click code snippet:

 

private void Button_Clicked(object sender, EventArgs e)

{

viewModel.AxisColor = viewModel.AxisColor == Colors.Red ? Colors.Blue : Colors.Red;

}


We have attached the sample for your reference; you can review the sample for more information.

 

Please reach out if you need further assistance.

 

Best regards,

Arul Jenith B.



Attachment: AxisLineTest_9d574e3e.zip


JK Jon Kao March 5, 2025 01:41 PM UTC

Hi Syncfusion Team,


Thank you for your prompt response and guidance. I really appreciate your support.


Best regards.



PR Preethi Rajakandham Syncfusion Team March 6, 2025 04:40 AM UTC

Hi Jon Kao,

You are welcome. Please let us know if you need further assistance. As always, we are happy to help you out.

Regards,

Preethi R



Loader.
Up arrow icon