We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to display the modified axis labels in .NET MAUI Charts

Hi!

Can you help me? I didn't find in MAUI how to do it.

In Xamarin.Forms 

https://support.syncfusion.com/kb/article/5614/how-to-display-the-modified-axis-labels-in-xamarin-forms-charts

But in Maui?


7 Replies

NT Nitheeshkumar Thangaraj Syncfusion Team July 31, 2023 01:34 PM UTC

Hi Davi,

We have validated your query and have already logged it as a feature request. Please find the link below:

https://www.syncfusion.com/feedback/45586/support-to-retrieve-visible-axis-labels-collection-in-net-maui-cartesian-chart


However, we have achieved the modified axis label with the help of the label created event in the axis. The code snippet is attached below:


private void NumericalAxis_LabelCreated(object sender, Syncfusion.Maui.Charts.ChartAxisLabelEventArgs e)

    {

        double start = e.Position;

        var position = start;

     if(position == 0)

      {

       e.Label ="Low";

       }

     else if(position ==50)

     {

     e.Label = "High";

     }

 }


If you need any further assistance, feel free to ask.


Regards,

Nitheeshkumar



DF Davi Fabiano replied to Nitheeshkumar Thangaraj August 1, 2023 12:11 PM UTC

Hi Nitheeshkumar!


How do I access the ItemsSource in this method? I need to work with Axis data.

In Xamarin I used this:

// Get the series ItemsSource.

var itemsSource = (chart as SfChart).Series[0].ItemsSource;

Tks.



NT Nitheeshkumar Thangaraj Syncfusion Team August 2, 2023 12:15 PM UTC

Hi Davi,


Based on your query, achieving this ItemsSource can be done quite simply. The code snippet is provided below


Are you expecting any other way to accomplish this ItemsSource?


<chart:ColumnSeries x:Name="series"

                            ItemsSource="{Binding Data}"

                            XBindingPath="Name"

                            YBindingPath="Height"></chart:ColumnSeries>


private void NumericalAxis_LabelCreated(object sender, Syncfusion.Maui.Charts.ChartAxisLabelEventArgs e)

{

   Var ItemsSource = series.ItemsSource;

   double start = e.Position;

   var position = start;

   if(position == 0)

  {

    e.Label ="Low";

  }

  else if(position ==50)

 {

  e.Label = "High";

 }

}

 

 


Please let us know your exact use case or any concept art related to this, we will check possibility and provide you the runnable application.


Regards,

Nitheeshkumar.



DF Davi Fabiano replied to Nitheeshkumar Thangaraj August 4, 2023 12:06 PM UTC

Hi  Nitheeshkumar!


I did as you asked but it does not recognize!

Can you help me?

Thanks!



NT Nitheeshkumar Thangaraj Syncfusion Team August 7, 2023 07:43 AM UTC

Hi Davi,


Based on the provided snapshot, there are no issues at the control level; the issue may exists at the application level. First and foremost, you need to delete the 'bin' and 'obj' folders from your application files. Please follow the suggestions below


  • Code-Behind: Make sure you are trying to access the named element in the correct code-behind file (the C# file associated with the XAML file). If you're trying to access it from a different file, you might need to use the x:FieldModifier="public" attribute in your XAML to expose the named element to other classes.
  • Namespace and Assembly References: Verify that the namespace declarations and assembly references are correct in both your XAML and C# files. If they're not aligned, you might not be able to access the named element.
  • Check for Typos: Double-check for any typos or syntax errors in both the XAML and C# code. Even a small mistake can prevent proper access.
  • Debugging: If you're still having trouble, try debugging your code. Set breakpoints in your C# code where you're trying to access the named element and step through the code to see if you can identify where the issue is occurring.
  • Visibility: If the named element is nested within a control that is not visible (e.g., part of a collapsed panel), you might not be able to access it until it becomes visible.
  • Event Handlers: If you're trying to handle events from a named element, make sure you've correctly attached event handlers in your C# code.

We hope it helps. If you need any further assistance, feel free to ask.


Regards,

Nitheeshkumar



DF Davi Fabiano replied to Nitheeshkumar Thangaraj August 7, 2023 01:05 PM UTC

Hi!


I created an example with the problem!

Can you help me?

Tks.


40Image_9825_1691413469625


Attachment: MauiAppChart_b0d2ddd3.zip


NT Nitheeshkumar Thangaraj Syncfusion Team August 8, 2023 01:49 PM UTC

Hi Davi,


Based on the sample you provided, the series is located within the Data template, which is why we cannot extract the series name in the LabelCreated event. As an alternative solution, we ability to retrieve the itemsSource from the sender of the LabelCreated event . The corresponding code snippet is provided below. We hope it helps you.


private void secondaryAxis_LabelCreated(object sender, ChartAxisLabelEventArgs e)

    {

        var axis = sender as ChartAxis;

        var source = axis.BindingContext;

        var itemsSource = source as ChartCollectionModel;

        var xValues = itemsSource.Description;

        var yValues = itemsSource.Valor;

   }


Regards,

Nitheeshkumar.


Loader.
Up arrow icon