You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -3,144 +3,153 @@ This article provides a detailed walkthrough on how to add multiple trackballs i
3
3
4
4
Learn step-by-step instructions and gain insights to add multiple trackballs in a WPF SfChart.
5
5
6
-
**Step 1:**Create a custom ChartTrackBallBehaviorExt class, which is inherited from [ChartTrackballBehavior](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.ChartTrackBallBehavior.html#).
6
+
**Step 1:**Initialize the SfChart with primary and secondary axes. For more detailed steps, refer to the WPF Charts [documentation](https://help.syncfusion.com/wpf/charts/getting-started).
**Step 2:** In the constructor of your MainWindow class, initialize the trackballs by setting their SfChart property to the chart defined in your XAML. This ensures that the trackballs are associated with the correct chart instance and can be accessed in other classes.
15
+
<chart:SfChart.PrimaryAxis>
16
+
<chart:CategoryAxis/>
17
+
</chart:SfChart.PrimaryAxis>
18
18
19
-
C#
19
+
<chart:SfChart.SecondaryAxis>
20
+
<chart:NumericalAxis/>
21
+
</chart:SfChart.SecondaryAxis>
20
22
21
-
```csharp
22
-
publicpartialclassMainWindow : Window
23
-
{
24
-
publicMainWindow()
25
-
{
26
-
InitializeComponent();
27
-
trackball1.SfChart=this.chart;
28
-
trackball2.SfChart=this.chart;
29
-
}
30
-
}
23
+
<chart:LineSeriesItemsSource="{Binding Data}"
24
+
XBindingPath="Day"
25
+
YBindingPath="CPULoad" >
26
+
</chart:LineSeries>
27
+
28
+
</chart:SfChart>
29
+
30
+
</Grid>
31
+
```
32
+
33
+
**Step 2:** Create a custom ChartTrackBallBehaviorExt class, which is inherited from [ChartTrackballBehavior](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.ChartTrackBallBehavior.html#).
**Step 3:** Create instances of ChartTrackBallBehaviorExt, and add them to the [Behaviors](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.SfChart.html#Syncfusion_UI_Xaml_Charts_SfChart_Behaviors) collection, assigning specific names to each.
**Step 4:**Override the **OnContentRendered** methodto run the asynchronous task that calls ShowTrackball().
55
+
**Step 4:**Implement the **ChartTrackBallBehaviorExt**class and its functionalities. Include the **Display**method, which is responsible for displaying the trackball at specified coordinates by setting the IsActivated protected property of the ChartTrackBallBehavior class. Manage multiple trackballs by overriding **mouse event handlers** in ChartTrackBallBehavior, using the **FindNearestTrackball** method in **OnMouseEnter**to locate the closest trackball. The **isTrackballActive** variable ensures only the active trackball responds to the events.
**Step 6:** Implement the **Display** method, which is responsible for displaying the trackball at specified coordinates . It updates the trackball’s position, sets the IsActivated protected property of the ChartTrackBallBehavior class to true, and triggers the necessary internal methods to reflect these changes on the UI.
**Step 7:** The **SetInternalProperty** method uses reflection to set an internal property of an object. This is useful for accessing and modifying properties that are not publicly accessible.
@@ -149,113 +158,67 @@ public class ChartTrackBallBehaviorExt : ChartTrackBallBehavior
149
158
break;
150
159
}
151
160
}
152
-
}
153
-
. . .
154
-
}
155
-
```
156
-
157
-
**Step 8:** The **InvokeInternalMethod** method uses reflection to invoke an internal method of an object. This allows calling methods that are not publicly accessible.
**Step 9:**Interact with multiple trackballs by overriding the **Mouse Event handlers** of [ChartTrackBallBehavior](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Charts.ChartTrackBallBehavior.html) class. The **FindNearestTrackball** method is called in **OnMouseEnter** method to find the nearest trackball to the mouse pointer. The **isTrackballActive**variable is used to track whether a specific trackball is currently active, ensuring that only the relevant trackball responds to mouse events.
172
+
**Step 5:**In the constructor of your MainWindow class, initialize the trackballs by setting their SfChart property to the chart defined in your XAML. This ensures that the trackballs are associated with the correct chart instance and accessible in other classes. Override the **OnContentRendered** method to run an asynchronous task that calls ShowTrackball(). Implement the **ShowTrackball**method to calculate positions and display the trackballs at load time using the Display method.
**Step 10:** The **FindNearestTrackball** method identifies the trackball closest to the user’s touch point, determining which trackball should be activated or moved based on user interaction.
// Update the nearest trackball if the current one is closer
244
-
if (distance<minDistance)
245
-
{
246
-
minDistance=distance;
247
-
nearestTrackball=trackball;
248
-
}
249
-
}
250
-
}
251
-
252
-
returnnearestTrackball;
214
+
// Display the second trackball
215
+
trackball2.Display(xPosition1, yPosition1);
216
+
});
253
217
}
254
-
. . .
255
-
}
256
-
```
218
+
}
219
+
```
257
220
258
-
**Step 11:** To control the trackballs, simply hover over them with your mouse. As you move the mouse within the chart area, the trackball will follow the cursor, allowing you to inspect different data points interactively.
221
+
**Step 6:** To control the trackballs, simply hover over them with your mouse. As you move the mouse within the chart area, the trackball will follow the cursor, allowing you to inspect different data points interactively.
0 commit comments