GestureRecognizer in Chart background

Hi,

I've a quite simple bar chart in my application. Tooltips are used when a user taps on a bar. However, I want/need to implement another functionality. If the user taps in the area of the chart, but not on a bar, a command should be executed (an event would work too). 
I've already added GestureRecognizers to the Chart and to the parent container, but that doesn't work too well. Ideally there would be some background tapped/clicked event or something similar. 

Is there some way to achieve this?

I hope the attached image helps to clarify my intention (pro level paint.net skills ;-)




2 Replies 1 reply marked as answer

SJ Suyamburaja Jayakumar Syncfusion Team November 12, 2020 04:09 PM UTC

Hi Biss-Fotec,  
   
Greetings from Syncfusion.  
  
We would like to let you know that due to having the default touch interactive features, touch has been handled at the source itself. So, the gesture of the chart will not invoke. We will try to achieve this through any of the possible workaround and update you on the possibilities of workaround preparation on or before November 16, 2020. 
 
Regards, 
Suyamburaja J. 



SJ Suyamburaja Jayakumar Syncfusion Team November 17, 2020 02:47 PM UTC

Hi Biss-Fotec,  
   
Thanks for your patience.   
   
We would like to let you know that your requirement has been achieved by using workaround sample with extending the ChartBehavior and on its touch down method, invoke the AreaClicked event in the custom chart with ensuing the whether the tapped position has segment or not with the following code snippet  
 
ChartExt and ChartBehaviorExt: 
public class ChartBehaviorExt : ChartBehavior 
    { 
        public ChartExt chart { get; set; } 
        public ChartBehaviorExt() 
        { 
 
        } 
 
        protected override void OnTouchDown(float pointX, float pointY) 
        { 
            if (chart != null) 
            { 
                foreach (var data in chart.Series) 
                { 
                    var segementCount = (data.ItemsSource as ObservableCollection<Model>).Count; 
                    var seriesBounds = data.GetDataPointIndex(pointX, pointY); 
                    if (!(seriesBounds < segementCount && seriesBounds > 0)) 
                    { 
                        chart.RaiseClicked(new EventArgs()); 
                    } 
                } 
 
            } 
        } 
    } 
 
    public class ChartExt : SfChart 
    { 
 
        public event EventHandler<EventArgs> AreaClicked; 
 
        internal void RaiseClicked(EventArgs args) 
        { 
            this.AreaClicked?.Invoke(this, EventArgs.Empty); 
        } 
 
    } 
 
XAML: 
<local:ChartExt x:Name="chart1" HorizontalOptions="FillAndExpand" AreaClicked="chart1_AreaClicked" VerticalOptions="FillAndExpand"> 
             . . . . .       
                <chart:SfChart.ChartBehaviors> 
                    <local:ChartBehaviorExt chart="{x:Reference chart1}" ></local:ChartBehaviorExt> 
                                                          </chart:SfChart.ChartBehaviors> 
                                           </local:ChartExt> 
 
 
Please let us know if you need any further assistance.  
 
Regards, 
Suyamburaja J. 


Marked as answer
Loader.
Up arrow icon