Double click chart series in IOS application

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
incadea
Newbie
Newbie
Posts: 20
Joined: Thu Jul 05, 2012 12:00 am

Double click chart series in IOS application

Post by incadea » Tue Jul 24, 2012 12:05 pm

Hello,
I am developing an ios application using Teechart. I have created a bar chart. Now want 2 events :
1.) single tap/click on series : to display tooltip of x and y axes values.
2.) Double tap/click series : to drill down the chart.

I am able to find out the code for single click on series as follows:
this.chart.ClickSeries += (sender, s, valueIndex, e) =>
{ };

Please let me know how can i catch the double click on chart series. Sample code would be helpful.


Thanks

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Double click chart series in IOS application

Post by Yeray » Fri Jul 27, 2012 9:21 am

Hi,

Take a look at the discussion here:
http://www.teechart.net/support/viewtop ... recognizer

Instead of using the clickBackGround event, you could use the clickSeries. Then, you could use the uirecognizer parameter to know what kind of gesture has arrived and the numberOfTouches.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

incadea
Newbie
Newbie
Posts: 20
Joined: Thu Jul 05, 2012 12:00 am

Re: Double click chart series in IOS application

Post by incadea » Tue Jul 31, 2012 6:04 am

Hi Yeray,

I am able to find double click on my chart.
Following is my code:

Code: Select all

var tapRecognizerSingle = new UITapGestureRecognizer(this,new MonoTouch.ObjCRuntime.Selector("HandleTapFromDouble"));
tapRecognizerSingle.NumberOfTapsRequired = 2;
tapRecognizerSingle.Delegate = new GestureDelegate();
this.chart.AddGestureRecognizer(tapRecognizerSingle);

  [Export("HandleTapFromDouble")]
            public void HandleTapFromDouble (UITapGestureRecognizer recognizer)
            {               
               new UIAlertView("Double", "No of touches: " + recognizer.NumberOfTouches.ToString(),null,"OK",null).Show();           
            }

    // delegate methods for UITapGestureRecognizer
    public class GestureDelegate : UIGestureRecognizerDelegate
    {
        public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
        {
        return true;
        }
        public override bool ShouldBegin (UIGestureRecognizer recognizer)
        {
        return true;
        }
        public override bool ShouldRecognizeSimultaneously (UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
        {
        return true ;
        }
    }

recognizer.NumberOfTouches.ToString() always gives me 1.

but my requirement is to find double and single click on CHART SERIES and find out the clicked x and y axes values.

For single click we already have ClickSeries event.

Code: Select all

this.chart.ClickSeries += (sender, s, valueIndex, e) => 
            {
string Yvalue = s.YValues [valueIndex].ToString();
                string Xvalue = s.XValues [valueIndex].ToString();
                string Title = s.Title;

                string MarkValue = s.LegendString(valueIndex, LegendTextStyles.Plain);

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Re: Double click chart series in IOS application

Post by Pep » Thu Aug 02, 2012 8:43 am

Hello,

I've been looking at the code you are using. The first code will add the gesture to the Chart, but not just to the Series of the Chart. In the case you want to control the touch over the Chart you could use the ClickBackground event, as it's used into the post Yeray said, there you should be able to control the numberoftouches used in recognizer.

Please do not hesitate to contact us if you still having problems.

incadea
Newbie
Newbie
Posts: 20
Joined: Thu Jul 05, 2012 12:00 am

Re: Double click chart series in IOS application

Post by incadea » Fri Aug 03, 2012 6:36 am

Hello

Thanks for your reply.
ClickBackground event will not serve my purpose. I want to find click on series event in following two cases;
1.) Single click on chart series only (not the background of the chart.) . For this we have [this.chart.ClickSeries += (sender, s, valueIndex, e) => ]
2.) Double click on chart series only (not the background of the chart.)

Please let me know how can i capture double click on chart series. And i want clicked series x and y axes values on double click.

Thanks

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Re: Double click chart series in IOS application

Post by Pep » Fri Aug 03, 2012 8:12 am

Hello,

Ok, I'm going to prepare an example code and send it to you asap.

incadea
Newbie
Newbie
Posts: 20
Joined: Thu Jul 05, 2012 12:00 am

Re: Double click chart series in IOS application

Post by incadea » Thu Aug 09, 2012 6:17 am

Thanks Josep

I am waiting..

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Re: Double click chart series in IOS application

Post by Pep » Mon Aug 13, 2012 10:54 am

Hello,

sorry for delay, here an example of code which allows to catch double tap into the Chart view, and also checks if tap has been done over the Series pointer, hope that it helps :

Code: Select all

// This method could be called insode the ViewDidLoad 
		WireUpTapGestureRecognizer ();

		protected void WireUpTapGestureRecognizer ()
		{
			// create a new tap gesture
			UITapGestureRecognizer tapGesture = new UITapGestureRecognizer ();
			// wire up the event handler (have to use a selector)
			tapGesture.AddTarget ( () => {

				Console.WriteLine("Chart tapped @" + tapGesture.LocationOfTouch (0, (UIView)_controller.chartController.View).ToString ());
				if (_controller.chartController.chart.Series[0].Clicked(Point.Round(tapGesture.LocationOfTouch(0, (UIView)_controller.chartController.View)))==1)
					Console.WriteLine("Series double clicked");
			});
			// configure it
			tapGesture.NumberOfTapsRequired = 2;
			// add the gesture recognizer to the view
			_controller.chartController.View.AddGestureRecognizer (tapGesture);
		}

incadea
Newbie
Newbie
Posts: 20
Joined: Thu Jul 05, 2012 12:00 am

Re: Double click chart series in IOS application

Post by incadea » Tue Aug 14, 2012 9:57 am

Hello Josep,

Thanks for the sample code. It was very useful.

Following is my final code to drill on double click of chart series:

Code: Select all

protected void WireUpTapGestureRecognizer()
        {
            // create a new tap gesture
            UITapGestureRecognizer tapGesture = new UITapGestureRecognizer();
            // configure it
            tapGesture.NumberOfTapsRequired = 2;
            // wire up the event handler (have to use a selector)
            tapGesture.AddTarget(() => {            
                      
                Steema.TeeChart.Styles.Series s = this.chart.Series [0];   
                int valueIndex = s.Clicked(Point.Round(tapGesture.LocationOfTouch(0, (UIView)this.chartView)));        
                             
                int iSeriesCount = this.chart.Series.Count;
                int iCounter = 1;
                for (iCounter=1; iCounter<=iSeriesCount; iCounter ++)
                {
                    if (this.chart.Series.Count >= iCounter)
                    {
                        s = this.chart.Series [iCounter - 1];   
                        valueIndex = s.Clicked(Point.Round(tapGesture.LocationOfTouch(0, (UIView)this.chartView)));    
                        if (valueIndex >= 0)
                        {
                            DrillChartOnClick(s, valueIndex);
                        }
                    }
                }
            }
            );
            // add the gesture recognizer to the view
            this.chartView.AddGestureRecognizer(tapGesture);
        }

Pep
Site Admin
Site Admin
Posts: 3303
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Re: Double click chart series in IOS application

Post by Pep » Tue Aug 14, 2012 10:24 am

Hi,

ok, I'm glad to hear that. :)

best regards !

Post Reply