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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DateTimeAxis date/time display format on label?

Thread ID:

Created:

Updated:

Platform:

Replies:

124543 Jun 13,2016 02:14 PM UTC Oct 19,2016 12:56 PM UTC Xamarin.Forms 6
loading
Tags: SfChart
Jeff Lindborg
Asked On June 13, 2016 02:14 PM UTC

I'm working on localizing my app and changing language/cultures requires formatting date/time per local standards - setting my charts to use the primary axis of DateTimeAxis works fine but the date format displayed looks to be hard coded to dd/MM/YYYY - is there a way to adjust this or a mechanism similar to the custom display template for ToolTips or the like?
thanks


Saravana Pandian Murugan [Syncfusion]
Replied On June 14, 2016 07:33 AM UTC

Hi Jeff, 
We can format the axis labels using LabelFormat property of ChartAxis. Also, we can get the actual labels using LabelCreated event of ChartAxis for advanced customization. 
Please find the below code example on how to customize axis labels. 
Code Example: 
C#: 
 
DateTimeAxis dateTimeAxis = new DateTimeAxis(); 
 
//Using this event we can get the actual labels and position. 
dateTimeAxis.LabelCreated += dateTimeAxis_LabelCreated; 
 
//This code is used to apply the label format to ChartAxis labels. 
dateTimeAxis.LabelStyle.LabelFormat = "dd/MM/yyyy"; 
 
 
void dateTimeAxis_LabelCreated(object sender, ChartAxisLabelEventArgs e) 
{ 
} 
 
You can refer to the following user guide link to know more details, 
 
Thanks, 
Saravana Pandian M. 
  


idispose
Replied On September 2, 2016 03:13 PM UTC

Can you do that in XAML? 

Magesh Kumar Krishnan [Syncfusion]
Replied On September 5, 2016 06:57 AM UTC

Hi Jeff,

Please find the below code example on” how to customize axis labels in Xaml”.

Code Example:
Xaml:   
 
   
<chart:SfChart.PrimaryAxis>   
        <chart:DateTimeAxis x:Name="dateTimeAxis" LabelCreated="dateTimeAxis_LabelCreated">   
          <chart:DateTimeAxis.LabelStyle>   
            <chart:ChartAxisLabelStyle LabelFormat="dd/MM/yyyy"/>   
          </chart:DateTimeAxis.LabelStyle>   
        </chart:DateTimeAxis>   
</chart:SfChart.PrimaryAxis>   
   
 
  
 Regards, 
Magesh 


Martin Dusek
Replied On October 18, 2016 06:26 PM UTC

This xaml code causes my app to crash.

    <chart:SfChart HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
      <chart:SfChart.PrimaryAxis>
        <chart:DateTimeAxis x:Name="axis" Minimum="{Binding Min}" Maximum="{Binding Max}">
          <chart:DateTimeAxis.LabelStyle>   
            <chart:ChartAxisLabelStyle LabelFormat="hh:mm:ss"/>   
          </chart:DateTimeAxis.LabelStyle>
        </chart:DateTimeAxis>
      </chart:SfChart.PrimaryAxis>
      <chart:SfChart.SecondaryAxis>


When I remove

          <chart:DateTimeAxis.LabelStyle>   
            <chart:ChartAxisLabelStyle LabelFormat="hh:mm:ss"/>   
          </chart:DateTimeAxis.LabelStyle>

then my app works. I use latest Xamarin.Forms with latest SfChart nuget packages. Can you please help?

Martin Dusek
Replied On October 18, 2016 06:27 PM UTC

Also please note C# code

axis.LabelStyle.LabelFormat = "hh:mm:ss";

works well for me. But I would like to have label format in xaml.

Jaikrishna Chandrasekar [Syncfusion]
Replied On October 19, 2016 12:56 PM UTC

Hi Martin,

We are unable to reproduce the issue at our end. We have prepared a sample based on the provided code snippet which can be downloaded from

Sample: http://www.syncfusion.com/downloads/support/forum/124543/ze/LineChart-67480747

Note : If you are still facing the issue, please give more information about the nugget packages version you are using or revert us with the modified sample which will be helpful for us to serve you better.

Regards,
Jaikrishna C

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.

Warning Icon 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.Close Icon

;