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

DateTimeAxis date/time display format on label?

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


6 Replies

SP Saravana Pandian Murugan Syncfusion Team 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. 
  



ID idispose September 2, 2016 03:13 PM UTC

Can you do that in XAML? 


MK Magesh Kumar Krishnan Syncfusion Team 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 



MD Martin Dusek 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?


MD Martin Dusek 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.


JC Jaikrishna Chandrasekar Syncfusion Team 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

Loader.
Up arrow icon