Format number in Y-axis with Culture

Hi,

Is it possible to set the Y-axis with a Culture, like nl-NL?

8 Replies

DS Durgadevi Selvaraj Syncfusion Team January 31, 2018 04:04 PM UTC

Hi Vince, 
 
Thanks for contacting Syncfusion Support. 
 
We have analyzed your requirement and it can be achieved using LabelCreated event of secondary axis as shown in below code, 
 
Code Snippet[XAML] 
  NumericalAxis secondaryAxis = new NumericalAxis(); 
  secondaryAxis.LabelCreated += SecondaryAxis_LabelCreated; 
  chart.SecondaryAxis = secondaryAxis; 
 
private void SecondaryAxis_LabelCreated(object sender, ChartAxis.LabelCreatedEventArgs e) 
{ 
            var label = (sender as ChartAxisLabel).LabelContent; 
            double yVal = Convert.ToDouble(label); 
            label = yVal.ToString("0.000", new CultureInfo("nl-NL")); 
} 
 
 
Please find the reference sample from below link, 
 
Please let us know if you have any concerns. 
 
Regards,  
Durgadevi S 



VI Vince January 31, 2018 05:24 PM UTC

Hi Durgadevi,

It works. Thanks!

In my app the values of the secondaryAxis are 'long' types so I changed your code "double val = Convert.ToDouble(label.LabelContent);" in "long val = Convert.ToInt64(label.LabelContent);".

With this changed code a value of "160000" becomes "160.000" which is correct. Now I want to add a Euro sign so that "160000" becomes "€ 160.000". How can a achieve that?


DV Divya Venkatesan Syncfusion Team February 1, 2018 06:44 AM UTC

Hi Vince, 
 
Please set the string format as shown in the below code snippet. 
 
label.LabelContent = val.ToString("0.0000", new CultureInfo("nl-NL")); 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Divya Venkatesan 
 



VI Vince February 1, 2018 08:12 AM UTC

Hi Divya,

It works. Thanks for your support.


VI Vince February 1, 2018 10:59 AM UTC

Hi,

I also tried to set the Culture for the Tooltip but it failed using the next code:

            chart.TooltipCreated += (sender, e) =>
            {
                var label = e.P1;
                long yVal = Convert.ToInt64(label.TooltipText); <== Unexpected Error
                ...
            };

Instead I used the nect code but it has no options to set the Culture:

            ChartTooltipBehavior tool = new ChartTooltipBehavior();
            tool.LabelFormat = "€###,###,###";
            chart.Behaviors.Add(tool);

Do you have a solution?




DV Divya Venkatesan Syncfusion Team February 2, 2018 09:39 AM UTC

Hi Vince, 
 
You can set the culture for the Tooltip as shown in the below code snippet. 
 
chart.TooltipCreated += (sender, e) => 
            { 
                var label = e.P1.Label; 
                long yVal = Convert.ToInt64(label); 
                e.P1.Label = yVal.ToString("€0.0000", new CultureInfo("nl-NL")); 
            }; 
 
Please let us know, if you need any further assistance 
 
Regards, 
Divya Venkatesan 
 



VI Vince February 2, 2018 02:58 PM UTC

Hi Divya,

It works. Great!


DV Divya Venkatesan Syncfusion Team February 4, 2018 03:33 PM UTC

Hi Vince,

Thanks for the update.

We are glad to know that the given solution works.

Please let us know if you need any further assistance.

Regards,
Divya Venkatesan


Loader.
Up arrow icon