DateTime axis format

3 posts, 0 answers
  1. George
    George avatar
    62 posts
    Member since:
    Sep 2008

    Posted 24 Mar 2015 Link to this post


    I have succesfully implemeted the process of displaying a graph for xamarin IOS. I have an issue on the formating of the DateTime x axis. I use the following code to specify the axis, the end result should be the x axis to display months as:  Jan-15   Feb-15  MAr-15 .. etc

        TKChartDateTimeAxis xAxis = new TKChartDateTimeAxis();
         xAxis.MajorTickIntervalUnit = TKChartDateTimeAxisIntervalUnit.Months;
         this.MyChart.XAxis = xAxis;

    If I do not specify anything for the format property I get as a result the names of the months on the x axis, like the attached picture, with no indcation on the respective years. I get Öct Nov Dec etc" when I really want "Oct-14 Nov -14" etc. Can you please provide some feedback on how to accomplish the expected result?

    Also, in other implementations of the Chart control, like Unified Windows, you have a second option for the DateTime chart like "DateTimeContinuousAxis", which is very usefull for dispalying date data that does not fall into a serial mode, for example stock tick data. Is this option available for the xamarin IOS chart control?


  2. Yoanna
    Yoanna avatar
    44 posts

    Posted 24 Mar 2015 Link to this post

    Hello, George,

    thank you for contacting us.

    You can accomplish the desired effect by customizing the text for the axis labels. This can be done by implementing the TKChartDelegate protocol and overriding its chart:textForAxis:value:atIndex: method. By doing this you will be able to modify the text for the axis labels. Its easy to do this by using NSDateFormatter class. Consider the sample below:

    chart.Delegate = new ChartDelegate ();
    class ChartDelegate: TKChartDelegate
        public override string TextForAxis (TKChart chart, TKChartAxis axis, NSObject value, nuint index)
            if (axis.Position == TKChartAxisPosition.Bottom) {
                NSDateFormatter formatter = new NSDateFormatter ();
                formatter.DateFormat = "MMM - dd";
                return formatter.StringFor (value);
            return null;

    I hope this solves the issue. If you have any questions do not hesitate to contact us.


    See What's Next in App Development. Register for TelerikNEXT.

  3. Paresh
    Paresh avatar
    1 posts
    Member since:
    Jun 2015

    Posted 12 Aug 2015 in reply to Yoanna Link to this post

    Exactly what I was looking for. Thanks
Back to Top