Show TrackBallInfo on multiple charts at the same time

I have two different spline charts on two consecutive rows. Both of them have the same XBindinPath, but different YBindingPath. I have the following requirement for them -

  1. When I mouse over any one of the charts, both of them will show TrackBallInfo at the same point along with their corresponding values on that point


Can I get some suggestions to implement that in a cleaner way?
Here is a scratch of my design-



3 Replies

DD Devakumar Dhanapoosanam Syncfusion Team February 8, 2022 01:18 PM UTC

Hi HRahman, 
 
We have analyzed your query and achieved your requirement by using the multiple area support of chart using the ChartRowDefinition with multiple series based on your requirement in two rows and add the ChartTrackBallBehavior to show trackball for both chart row as per in the below code example. 
 
 
<chart:SfChart.RowDefinitions> 
    <chart:ChartRowDefinition/> 
    <chart:ChartRowDefinition/> 
</chart:SfChart.RowDefinitions> 
 
<chart:SfChart.PrimaryAxis> 
    <chart:DateTimeAxis LabelFormat="dd-MMM" ShowGridLines="False" 
                        TickLineSize="10"/> 
</chart:SfChart.PrimaryAxis> 
 
<chart:SfChart.SecondaryAxis> 
    <chart:NumericalAxis ShowGridLines="False" 
                         Minimum="0" Maximum="20"/> 
</chart:SfChart.SecondaryAxis> 
 
<chart:SplineSeries ItemsSource="{Binding Data}"  
                      XBindingPath="XValue" YBindingPath="YValue1"> 
</chart:SplineSeries> 
 
<chart:SplineSeries ItemsSource="{Binding Data}"  
                      XBindingPath="XValue" YBindingPath="YValue2"> 
    <chart:SplineSeries.YAxis> 
        <chart:NumericalAxis chart:SfChart.Row="1" ShowGridLines="False" PlotOffsetStart="30" 
                             Minimum="0" Maximum="10"/> 
    </chart:SplineSeries.YAxis> 
</chart:SplineSeries> 
 
<chart:SfChart.Behaviors> 
    <chart:ChartTrackBallBehavior LineStyle="{StaticResource lineStyle}"/> 
</chart:SfChart.Behaviors> 
 
 
Output: 
 
 
 
Please refer the below link for more details and let us know if you need any further assistance on this. 
 
 
Regards, 
Devakumar D 



HR HRahman replied to Devakumar Dhanapoosanam February 8, 2022 09:52 PM UTC

Thank you  Devakumar Dhanapoosanam for your reply.

But I need to show the charts separately, plus the charts will have their own header like, "Graph1" "Graph2" in the picture. I am trying to use two different charts for this. In that case, is there any way to control the TrackBall from the backend? So that, when I mouse over on any chart, this will enable the trackball of the other chart at the given point?

Note: I am following MVVM pattern.



DD Devakumar Dhanapoosanam Syncfusion Team February 9, 2022 01:15 PM UTC

Hi HRahman, 
 
We have achieved your requirement by using the MouseMove event of the chart and custom ChartTrackballBehaviorExt class to call the Show method of trackball while mouse moving in any chart as per the below code example.  
 
... 
<chart:SfChart Grid.Row="0" x:Name="chart1" 
               Header="Graph 1" 
               MouseMove="chart_MouseMove" > 
    …. 
    <chart:SfChart.Behaviors> 
        <local:ChartTrackBallBehaviorExt x:Name="trackball1" LineStyle="{StaticResource lineStyle}"/> 
    </chart:SfChart.Behaviors> 
</chart:SfChart> 
 
<chart:SfChart Grid.Row="1" x:Name="chart2" 
               Header="Graph 2" MouseMove="chart_MouseMove" > 
     
    <chart:SfChart.Behaviors> 
        <local:ChartTrackBallBehaviorExt x:Name="trackball2" LineStyle="{StaticResource lineStyle}"/> 
    </chart:SfChart.Behaviors> 
</chart:SfChart> 
 
 
private void chart_MouseMove(object sender, MouseEventArgs e) 
{ 
    var chart = sender as SfChart; 
    Point mousePoint = new Point 
    { 
        X = e.GetPosition(chart).X - chart.SeriesClipRect.Left - chart.Margin.Left, 
        Y = e.GetPosition(chart).Y - chart.SeriesClipRect.Top - chart.Margin.Top 
    }; 
 
    ShowTrackball(mousePoint.X, mousePoint.Y); 
} 
 
private void ShowTrackball(double x, double y) 
{ 
    tracball1.Show((float)x, (float)y); 
    tracball2.Show((float)x, (float)y); 
} 
 
public class ChartTrackBallBehaviorExt : ChartTrackBallBehavior 
{ 
    ... 
    public void Show(float x, float y) 
    { 
        IsActivated = true; 
        var point = new Point(x, y); 
 
        SetInternalProperty(typeof(ChartTrackBallBehavior), this, point, "CurrentPoint"); 
        base.OnPointerPositionChanged(); 
 
        InvokeInternalMethod(typeof(ChartTrackBallBehavior), this, "Activate", IsActivated); 
    }  
     
} 
 
 
Output: 
 
 
Please refer the below link for more details 
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Devakumar D 


Loader.
Up arrow icon