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 find CGPoint of Marker in a Series

I have a created an SFChart with a SFChartTrackballBehavior instance and can this there is a "Show" method on it to call SFChartTrackballBehavior.Show(CGPoint) which I can call manually and can see it will draw a trackball line on my chart correctly when called if I pass in a random CGPoint in the boundaries of my chart. But I can't see any methods to allow me to determine the CGPoint of a Data Marker when I reference one in code so that I can pass this to SFChartTrackballBehavior.Show(CGPoint) so I can manually draw the TrackBall at the position. Is there a way of determining the CGPoint of a Marker / Data Point on the chart so I can draw the trackball there manually ? 



3 Replies

MP Michael Prabhu M Syncfusion Team December 7, 2018 07:35 AM UTC

Hi Gavin Bryan, 

Greetings from Syncfusion. We have achieved your requirement by using ValueForPoint method in SFChart to convert the datapoint value to CGPoint. ValueForPoint method returns the corresponding CGPoint for individual chart axis. You can enable the trackball by passing the xvalue,yvalue to Show method which returns from the  ValueForPoint method with the corresponding DataPoint value. Please refer below code snippet. 

Code Snippet[C#] 

void Button_TouchUpInside(object sender, EventArgs e) 
{ 
            Model data = model.Data[2] as Model; 
            double xvalue = chart.PointForValue(data.XValue, chart.PrimaryAxis); 
            double yvalue = chart.PointForValue(data.YValue, chart.SecondaryAxis); 
 
            trackballBehavior.Show(new CoreGraphics.CGPoint(xvalue, yvalue)); 
 
} 

 

We have prepared sample for your requirement in NumericalAxis for PrimaryAxis. You can download the sample from the below link. 

Sample: 141333 

Note : 
1.      If you are using CategoryAxis or DateTimeCategoryAxis as PrimaryAxis , you can pass directly pass the xvalue as datapoint index instead of xvalue for PointForValue method. Please refer below code snippet. 

           Code Snippet[C#] 

void Button_TouchUpInside(object sender, EventArgs e) 
{ 
            Model data = model.Data[2] as Model; 
            double xvalue = chart.PointForValue(2,chart.PrimaryAxis); 
            double yvalue = chart.PointForValue(data.YValue, chart.SecondaryAxis); 
 
            trackballBehavior.Show(new CoreGraphics.CGPoint(xvalue, yvalue)); 
 
} 

 

2.      If you are using DateTimeAxis as PrimaryAxis , you have to convert the datetime value to double for PointForValue method. Please refer below code snippet. 

           Code Snippet[C#] 

void Button_TouchUpInside(object sender, EventArgs e) 
{ 
            Model data = model.Data[2] as Model; 
 
            double xvalue = chart.PointForValue(ToOADate (data.XValue),chart.PrimaryAxis); 
            double yvalue = chart.PointForValue(data.YValue, chart.SecondaryAxis); 
 
            trackballBehavior.Show(new CoreGraphics.CGPoint(xvalue, yvalue)); 
 
} 

DateTime BaseDate = new DateTime(1899, 12, 30);  
 public double ToOADate(DateTime time)  
{  
      return time.Subtract(BaseDate).TotalDays;  
}  


 

Thanks, 
Michael  



GB Gavin Bryan December 11, 2018 08:38 AM UTC

Thanks Michael, have got that working from your example.


MP Michael Prabhu M Syncfusion Team December 11, 2018 08:45 AM UTC

Hi Gavin, 
 
Glad we could help, feel free to contact us any time if you need any other assistance from us. 
 
Thanks, 
Michael 



Loader.
Live Chat Icon For mobile
Up arrow icon