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.
Unfortunately, activation email could not send to your email. Please try again.

Modifying the formatting of ChartAxisLabels

Thread ID:

Created:

Updated:

Platform:

Replies:

123591 Apr 1,2016 12:38 PM Apr 6,2016 08:00 AM WPF 5
loading
Tags: SfChart
Jeremie Clos
Asked On April 1, 2016 12:38 PM

Hello,

I have an issue when modifying my series, namely switching from a standard numerical axis to a logarithmic axis. Because my values are very low (between 0 and ~0.0000003), when switching to a standard numerical axis, they are all rounded to 0, which is not good. I have tried linking the following method to the LabelCreated event but to no avail - it's still a bunch of 0's which appear in the axis.

        private void XValueFormatter(object sender, LabelCreatedEventArgs e) {        
            double val = Convert.ToDouble(e.AxisLabel.LabelContent);
            if (Math.Abs(val) < 0.1)
                e.AxisLabel.LabelContent = val.ToString("G1", CultureInfo.InvariantCulture);
            else
                e.AxisLabel.LabelContent = val;
        }
What can I do to achieve my task?

Samuel Rajadurai Edwin Rajamanickam [Syncfusion]
Replied On April 4, 2016 08:20 AM

Hi Jeremie,

 

Thank you for contacting Syncfusion Support.

 

We have achieved your requirement by applying the required format for the axis label in LabelCreated event as like in the below code sample.

 

Code Snippet [C#]



 private void XValueFormatter(object sender, LabelCreatedEventArgs e)

  {

        var axisLabel = e.AxisLabel;

        axisLabel.LabelContent = string.Format("{0:0.#######}", axisLabel.Position);

  }

 

Regards,
Samuel


Jeremie Clos
Replied On April 4, 2016 10:59 AM

It still doesn't work for me, the labels are still all 0's. I know it's a displaying error because when I output the axisLabel.Position it gives me actual numbers (0.1, 0.2, etc.) while the axis still display 0, 0, and more 0's. Is there something else that could be at cause?

Sumathi Jayaraj [Syncfusion]
Replied On April 5, 2016 08:14 AM

Hi Jeremie,

Please confirm us, whether your requirement is to display the exact value or the exponential format of actual value. 

For example:

(1) 0.0000003 need to display as 3E-6, 
Code sample[C#]:

 
private void XAxisLabelFormatter(object sender, LabelCreatedEventArgs e)
{
    double val = e.AxisLabel.Position;
    //To display content in exponential format
    e.AxisLabel.LabelContent = val.ToString("G"CultureInfo.InvariantCulture);
}
 


(2) Need to display 0.0000003 as itself. 
Code sample[C#]:

 
private void XAxisLabelFormatter(object sender, LabelCreatedEventArgs e)
{
    var axisLabel = e.AxisLabel;
    axisLabel.LabelContent = string.Format("{0:0.#######}", axisLabel.Position);
}
 



Regards,
Sumathi J


Jeremie Clos
Replied On April 5, 2016 01:49 PM

I want it to follow the exponential formatting only if the value falls under a certain value, but it doesn't matter because it all gets rounded to 0 somehow. It looks like the following picture and as you can see, it's not a data problem because it is plotted correctly, at the right position, but the values are somehow rounded.
rounding to 0

Sumathi Jayaraj [Syncfusion]
Replied On April 6, 2016 08:00 AM

Hi Jeremie,

Thanks for the update.

We have prepared a sample to meet your requirements and it can be downloaded from the following location.

Sample: XAxisLabel_Sample

Regards,
Sumathi J

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;