Skip to content

Commit f432e7f

Browse files
Merge pull request #1 from SyncfusionExamples/WPF-61990-Update-readme
WPF-61990 Update readme
2 parents 7cead1c + a8e6b58 commit f432e7f

File tree

1 file changed

+81
-5
lines changed

1 file changed

+81
-5
lines changed

README.md

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,89 @@
1-
# How to add multiple trackball in Xamarin.iOS Chart
1+
# How to add multiple trackball in Xamarin.iOS Chart (SfChart)?
22

33
This example demonstrates how to add the multiple trackball to a single chart and drag them independently to view the information of different data points at the same time in Xamarin.iOS chart.
44

5-
See [How to add multiple trackball in Xamarin.iOS Chart](https://www.syncfusion.com/kb/10839?utm_medium=listing&utm_source=github-examples) for more details.
5+
SFChart allows you add multiple trackballs to a single chart and drag them independently to view the information of different data points at the same time.
66

7-
## <a name="requirements-to-run-the-demo"></a>Requirements to run the demo ##
7+
The following steps describe how to add multiple trackballs to SFChart.
88

9-
* [Visual Studio 2017](https://visualstudio.microsoft.com/downloads/) or [Visual Studio for Mac](https://visualstudio.microsoft.com/vs/mac/).
10-
* Xamarin add-ons for Visual Studio (available via the Visual Studio installer).
9+
**Step 1:** Create a custom ChartTrackballBehaviorExt class, which is inherited from **SFChartTrackballBehavior**.
10+
```
11+
public class ChartTrackballBehaviorExt : SFChartTrackballBehavior
12+
{
13+
}
14+
```
15+
16+
**Step 2:** Create an instance of ChartTrackballBehaviorExt and add it to the **Behaviors** collection.
17+
```
18+
ChartTrackballBehaviorExt trackballBehavior1 = new ChartTrackballBehaviorExt();
19+
ChartTrackballBehaviorExt trackballBehavior2 = new ChartTrackballBehaviorExt();
20+
chart.Behaviors.Add(trackballBehavior1);
21+
chart.Behaviors.Add(trackballBehavior2);
22+
```
23+
24+
**Step 3:** Activate the multiple trackballs at load time using the **[Show](https://help.syncfusion.com/cr/xamarin-ios/Syncfusion.SfChart.iOS.SFChartTrackballBehavior.html#Syncfusion_SfChart_iOS_SFChartTrackballBehavior_Show_CoreGraphics_CGPoint_)** method.
25+
```
26+
public override void ViewDidAppear(bool animated)
27+
{
28+
    base.ViewDidAppear(animated);
29+
 
30+
    trackballBehavior1.Show(pointX, pointY);
31+
    trackballBehavior2.Show(pointX, pointY);
32+
}
33+
```
34+
35+
**Step 4:** Set [ActivationMode](https://help.syncfusion.com/cr/xamarin-ios/Syncfusion.SfChart.iOS.SFChartTrackballBehavior.html#Syncfusion_SfChart_iOS_SFChartTrackballBehavior_ActivationMode) to [None](https://help.syncfusion.com/cr/Syncfusion.SfChart.iOS.SFChartTrackballActivationMode.html) to restrict the default movement of the trackball behavior.
36+
```
37+
trackballBehavior1.ActivationMode = SFChartTrackballActivationMode.None;
38+
trackballBehavior2.ActivationMode = SFChartTrackballActivationMode.None;
39+
```
40+
41+
**Step 5:** Interact with multiple trackballs by overriding the touch methods of SFChartTrackballBehavior class and the [HitTest](https://help.syncfusion.com/cr/xamarin-ios/Syncfusion.SfChart.iOS.SFChartTrackballBehavior.html#Syncfusion_SfChart_iOS_SFChartTrackballBehavior_HitTest_System_Single_System_Single_) method. The HitTest method is used to find the trackball that is currently activated by user.
42+
```
43+
public class ChartTrackballBehaviorExt : SFChartTrackballBehavior
44+
{
45+
    bool isActivated = false;
46+
 
47+
    public override void TouchesBegan(NSSet touches, UIEvent uiEvent)
48+
    {
49+
        if (touches?.AnyObject is UITouch touch)
50+
        {
51+
            CGPoint location = touch.LocationInView(Chart);
52+
            if (HitTest((float)location.X, (float)location.Y))
53+
            {
54+
                isActivated = true;
55+
                base.TouchesBegan(touches, uiEvent);
56+
            }
57+
        }
58+
    }
59+
 
60+
    public override void TouchesMoved(NSSet touches, UIEvent uiEvent)
61+
    {
62+
        if (isActivated)
63+
        {
64+
            if (touches?.AnyObject is UITouch touch)
65+
            {
66+
                CGPoint location = touch.LocationInView(Chart);
67+
                Show(location);
68+
                base.TouchesMoved(touches, uiEvent);
69+
            }
70+
        }
71+
    }
72+
 
73+
    public override void TouchesEnded(NSSet touches, UIEvent uiEvent)
74+
    {
75+
        isActivated = false;
76+
    }
77+
}
78+
```
79+
80+
**Step 6:** Tap and drag each trackball separately to view the data points at different positions simultaneously.
81+
82+
## Output:
83+
84+
![Multiple trackball in Xamarin.iOS Chart](https://user-images.githubusercontent.com/53489303/200624559-4d790a1d-35fb-4aa6-b977-028186b2b56c.gif)
85+
86+
KB article - [How to add multiple trackball in Xamarin.iOS Chart?](https://www.syncfusion.com/kb/10839/how-to-add-multiple-trackball-in-xamarin-ios-chart)
1187

1288
## <a name="troubleshooting"></a>Troubleshooting ##
1389
### Path too long exception

0 commit comments

Comments
 (0)