This is a migrated thread and some comments may be shown as answers.

DateTime axis format

2 Answers 123 Views
Chart
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 24 Mar 2015, 11:56 AM
Hi,

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?


Regards,

George

2 Answers, 1 is accepted

Sort by
0
Yoanna
Telerik team
answered on 24 Mar 2015, 04:58 PM
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.

Regards,
Yoanna
Telerik
 

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

 
0
Paresh
Top achievements
Rank 1
answered on 12 Aug 2015, 06:33 AM
Exactly what I was looking for. Thanks
Tags
Chart
Asked by
George
Top achievements
Rank 1
Answers by
Yoanna
Telerik team
Paresh
Top achievements
Rank 1
Share this question
or