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

Formatting labels on axes

How does one format labels on chart axes?
 
For example, if I have a series with dates on the primary axis (x axis) and want to format these labels to, say, "dd MMM", how do I do that?
 
I do not want to change the actual date values in the data used for the series. I want to change labels before rendering chart.

7 Replies

MK Magesh Kumar Krishnan Syncfusion Team February 12, 2015 10:55 AM UTC

Hi Steen,

Thanks for using Syncfusion Products.

We can achieve your requirement by using LabelFormat property of ChartAxis as shown in the below code snippet.

CodeSnippet:

[XAML] :

<chart:DateTimeAxis.LabelStyle>

            <chart:ChartAxisLabelStyle LabelFormat = "dd MMM"></chart:ChartAxisLabelStyle>

</chart:DateTimeAxis.LabelStyle

[C#] :

DateTimeAxis dateTimeAxis = new DateTimeAxis();

dateTimeAxis.LabelStyle.LabelFormat = "dd MMM ";


Please let us know if you require further assistance on this.

Thanks,

Magesh Kumar K



SS Steen Steiniche February 12, 2015 11:22 AM UTC

Hello Magesh Kumar K
 
Thanks for your reply. That works if I want to set an overall format rule.
 
I need more control than that, however. For instance, I might want to format only the first date of the month with "dd MMM" and all other dates in that month with just "dd". How is that achieved?
 
Thanks in advance
 
Steen


MK Magesh Kumar Krishnan Syncfusion Team February 13, 2015 07:05 AM UTC

Hi Steen,

We are glad to let you know that we have achieved your requirement by using a workaround. In this sample, we have written custom renderer for each platform for formatting individual labels in axis. We will provide this support in control level in any of our upcoming volume release.

Please find the workaround sample from the following attachment.

Sample: http://www.syncfusion.com/downloads/support/directtrac/118215/CustomAxisLabelFormat-1084686580.zip
 

Note:
While customizing individual axis labels in custom renderer for iOS, we faced an error while deploying it to an iPhone device. We have also fixed that error. Please replace the below attached Syncfusion.SfChart.iOS.dll in your “../lib/1.3/ios-unified” and “../lib/1.3/ios“paths in order to run the application on iPhone device.

Dll: http://www.syncfusion.com/downloads/support/directtrac/118215/Xamarian.iOS_Assemblies-83160372.zip

Please let us know if you require further assistance on this.

Thanks,
Magesh Kumar K



TW Tomasz Wisniewski February 24, 2015 07:56 PM UTC

Hello,
Date and time take some space horizontally, so on Windows Phone I displayed label in two rows: time on top (with "t" formatter, eg. 9:15 PM) and and date on bottom (MonthDayPattern, eg. Jan 1). I used LabelTemplate and and StackPanel inside of it. Is it possible to do something similar in Xamarin.Forms? I tried to achieve this with the custom renderer that you provided, however if I give string with two lines it renders in one line anyway. If I give for example TextView as LabelContent, it displays only class name. Do you have any ideas?

Thanks,
Tomasz


MK Magesh Kumar Krishnan Syncfusion Team February 25, 2015 01:18 PM UTC

Hi Thomasz,

We have created incident #135846 on behalf of you for this reported requirement. Our support engineer will assist you through incident under your Direct Trac account. So we request you to follow with the incident for further details.
Our Direct Trac support system can be accessed from the following link:
                               
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Please let us know if you require further assistance on this.

Thanks,
Magesh Kumar K


DM David Myers August 17, 2016 04:39 AM UTC

Hi,

Was a solution found to allow line breaks in axis labels? We'd also like to utilize this feature.


YP Yuvaraj Palanisamy Syncfusion Team August 18, 2016 07:08 AM UTC

Hi David, 

We have logged this as a feature request in our database. We will implement this feature in upcoming volume 2 service pack 2 release and it is estimated to be rolled in the end of August, 2016.  
 
Thanks, 
Yuvaraj 


Loader.
Live Chat Icon For mobile
Up arrow icon