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

How to converts the mouse point value to primary axis (date time axis) value

Hi,
I am using the wpf UI of Syncfusion to building a app for stock analysis and I am new for this. I want to implement the the multiple row chart with candle stick and volume only. Now I am implementing the autoscale Y when zooming Xaxis (date time axis). I use the SelectionZoomingEndEventArgs to get the selected area and converts the pixel value to chart value by PointToValue. However, the return value is not a date format. How can I get the date format? Below is my code. Thanks a lot for your assistance.
private void chart1_SelectionZoomingEnd(object sender, SelectionZoomingEndEventArgs e)
{
Point mousePointstart = new Point(e.ZoomRect.Left, e.ZoomRect.Top);
Point mousePointend = new Point(e.ZoomRect.Right, e.ZoomRect.Top);
double xValuestart = this.chart1.PointToValue(this.chart1.PrimaryAxis, mousePointstart);
double YValuestart = this.chart1.PointToValue(this.chart1.SecondaryAxis, mousePointstart);
double xValueend = this.chart1.PointToValue(this.chart1.PrimaryAxis, mousePointend);
double YValueend = this.chart1.PointToValue(this.chart1.SecondaryAxis, mousePointend);
double chartPointX = this.chart1.ValueToPoint(this.chart1.PrimaryAxis, xValuestart);
}

5 Replies

DA Devi Aruna Maharasi Murugan Syncfusion Team August 8, 2016 09:23 AM UTC

Hi Komatora, 
  
Thanks for contacting Syncfusion Support. 
  
The PointToValue method returns the DateTimeAxis axis value as double value of OLE automation date. This value can be converted in to its equivalent date time format, by using FromOADate extension method as shown in the below code snippet.  
  
[C#] 
 
     double xStart = chart.PointToValue(chart.PrimaryAxis, mousePointStart); 
     DateTime startDate = DateTime.FromOADate(xStart); 
  
We have prepared a demo sample based on your requirement and it can be downloaded from below link, 
  
  
Regards, 
Devi 






KO komatora August 9, 2016 05:11 AM UTC

Hi Devi,

Thanks for your reply and Demo. I have other question After checking your Demo, the return date value is not exactly the start and end point what I selected. The return value seems shift with a constant value. Attached please find the screen capture of the return value and selection screen.


Attachment: Selection_get_vale_ec383e38.zip


DA Devi Aruna Maharasi Murugan Syncfusion Team August 10, 2016 10:06 AM UTC

Hi Komatora, 
  
Thanks for your update. 
  
In order to get the exact position of chart area, we have to reduce the SeriesClipRect value to corresponding positon as shown in the below code.  
 
[C#] 
 
     Point mousePointStart = new Point(e.ZoomRect.Left - chart.SeriesClipRect.Left,  
 
                                           e.ZoomRect.Top - chart.SeriesClipRect.Top); 
 
     Point mousePointEnd = new Point(e.ZoomRect.Right - chart.SeriesClipRect.Left,  
  
                                    e.ZoomRect.Top - chart.SeriesClipRect.Top); 
  
We have modified the demo sample and it can be downloaded from below link, 
  
  
Please refer the below link to know about the axis value to pixel value conversion, 
  
  
Regards, 
Devi 





KO komatora August 17, 2016 03:46 PM UTC

Hi Devi,

Thanks for your updated samples and it is working fine.

And I want to confirm that can I change the Y axis's value when the zoom changed event is triggered? It got some error during run time. Please check the below code.

        private void chart_ZoomChanged(object sender, ZoomChangedEventArgs e)
        {


            NumericalAxis yAsix = new NumericalAxis()
            {
                Maximum = 890,
                Minimum = 820,
            };

            chart.SecondaryAxis = yAsix;


        }

Thank you



DA Devi Aruna Maharasi Murugan Syncfusion Team August 18, 2016 12:19 PM UTC

Hi komatora, 
  
Thanks for your update. 
  
We would like inform you that, we are unable to change the chart axis in Zoom changed event. Since we have calculated the zooming value based on axis and we cannot modify that Axes collection in that flow.  
  
Regards, 
Devi 


Loader.
Up arrow icon