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

Modifying the formatting of ChartAxisLabels

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?

5 Replies

SR Samuel Rajadurai Edwin Rajamanickam Syncfusion Team April 4, 2016 12:20 PM UTC

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



JC Jeremie Clos April 4, 2016 02:59 PM UTC

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?


SJ Sumathi Jayaraj Syncfusion Team April 5, 2016 12:14 PM UTC

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



JC Jeremie Clos April 5, 2016 05:49 PM UTC

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


SJ Sumathi Jayaraj Syncfusion Team April 6, 2016 12:00 PM UTC

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

Loader.
Up arrow icon