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

DateTimeCategoryAxis How to convert Axis coordinates to DateTime

Hi,
 
I'm changing from DateTimeAxis to DateTimeCategoryAxis.  (adviced by Syncfusion  http://www.syncfusion.com/support/forums/wpf/chart/115787 )
And some feature I had developped with DateTimeAxis are not working anymore with DateTimeCategoryAxis.
Especially Axis coordinates to DateTime conversion.  which is logical because I was using linear conversion and the DateTimeCategoryAxis is no linear.
For instance I was using :
var date = DateTime.FromOADate((double) cursor.X1);  //   with cursor typeof Syncfusion.UI.Xaml.Charts.VerticalLineAnnotation
or
var point = e.GetPosition(this.lineChart);  // with e typeof  MouseEventArgs
point.X = point.X - (yAxis.ActualWidth + lineChart.Margin.Left);
double xValue = lineChart.PointToValue(lineChart.PrimaryAxis, point);
var date =DateTime.FromOADate(xValue);   
 
What is the proper way to do such conversion with DateTimeCategoryAxis  ?
 
Regards,
Rodolphe

1 Reply

PR Prabakaran R Syncfusion Team April 4, 2014 12:17 PM UTC

Hi Rodolphe,

Thanks for using the Syncfusion products.

We have analysed the reported requirement, and you cannot get the exact Datetime value in DateTimeCategoryAxis just by converting FromOADate since values positioned by category not linear, instead of you can get the nearest point value by using following code snippet, also we have prepared a sample based on this, please find it from the below link.

 Code snippet [C#]:

 private void SfChart_MouseDown(object sender, MouseButtonEventArgs e)

        {

            var point = e.GetPosition(series);

            double x = 0d, y = 0d,stacked;

            series.FindNearestChartPoint(point, out x, out y, out stacked);

            var userProfile = series.ItemsSource as ObservableCollection<UserProfile>;//observable collection class where the data is set as items source for the series.

            MessageBox.Show(userProfile[(int)x].TimeStamp.ToString("MMM/dd/yyyy"));//display of datetime value where the mouse down event is clicked.

        }

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

Regards,

Prabakaran.


Attachment: DateTimeCategoryAxis_6d78e95a.zip

Loader.
Live Chat Icon For mobile
Up arrow icon