Tap handler for points in TKChartLineSeries

8 posts, 1 answers
  1. Muhammad
    Muhammad avatar
    7 posts
    Member since:
    Dec 2014

    Posted 08 Jan 2015 Link to this post

    I created TKChartLine with TKChartLineSeries, then I want to perform some function if I tap one of the points in series I added (with point's X as parameter). How to do this?
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 08 Jan 2015 Link to this post

    Hello Muhammad,

    You can use the chart:didSelectPoint: method from TKChartDelegate like demonstrated in this help article. Do not hesitate to write back if you need further assistance.

    Regards,
    Jack
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Muhammad
    Muhammad avatar
    7 posts
    Member since:
    Dec 2014

    Posted 08 Jan 2015 in reply to Jack Link to this post

    Thanks for your reply :)

    I have used that method but unfortunately the function is not called..

    here is my code:

    #import "ViewController.h"
    #import <TelerikUI/TelerikUI.h>
     
    @interface ViewController () <TKChartDelegate>
    @property (strong, nonatomic) UIScrollView *scrollView;
    @property (strong, nonatomic) TKChart *chart;
    @end
     
    @implementation ViewController
     
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, self.navigationController.navigationBar.frame.size.height, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
        [self.scrollView setUserInteractionEnabled:YES];
        [self.scrollView setBackgroundColor:[UIColor blackColor]];
        [self.scrollView setContentSize:CGSizeMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) + 1000)];
        [self.view addSubview:self.scrollView];
         
        // Membuat chart
        self.chart = [[TKChart alloc] initWithFrame:CGRectInset(self.view.bounds, 10, 10)];
        self.chart.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.chart.delegate = self;
        [self.scrollView addSubview:self.chart];
     
        NSMutableArray *randomNumericData = [[NSMutableArray alloc] init];
        TKChartDataPoint *point;
        for (int i = 0; i < 10; i++) {
            point = [[TKChartDataPoint alloc] initWithX:@(i) Y:@(arc4random()%100)];
            [randomNumericData addObject:point];
        }
         
        TKChartLineSeries *series = [[TKChartLineSeries alloc] initWithItems:randomNumericData];
        [series setSelectionMode:TKChartSeriesSelectionModeDataPoint];
        [series.style setPointShape:[[TKPredefinedShape alloc] initWithType:TKShapeTypeCircle andSize:CGSizeMake(18.0f, 18.0f)]];
        [self.chart addSeries:series];
        self.chart.title.hidden = NO;
        self.chart.title.text = @"My graphic";
        self.chart.legend.hidden = NO;
        self.chart.allowAnimations = YES;
        self.chart.xAxis.allowZoom = YES;
    }
     
    - (void)chart:(TKChart *)chart didSelectPoint:(id<TKChartData>)point inSeries:(TKChartSeries *)series atIndex:(NSInteger)index
    {
        NSLog(@"A point tapped!");
    }
     
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
     
    @end

    am I missing something?
  5. Muhammad
    Muhammad avatar
    7 posts
    Member since:
    Dec 2014

    Posted 08 Jan 2015 Link to this post

    By the way, circle point's color did changed when I tapped it, but chart:didSelectPoint: method didn't called
  6. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 09 Jan 2015 Link to this post

    Hello Muhammad,

    I tested your code with our latest official release - Q3 2014 1204. The method is being called. Please, could you confirm that you are using our latest release?

    Regards,
    Jack
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Muhammad
    Muhammad avatar
    7 posts
    Member since:
    Dec 2014

    Posted 13 Jan 2015 in reply to Jack Link to this post

    Hello Jack,

    I updated the framework to latest release, and yeah, it worked. Thank you! :)
  8. Giang
    Giang avatar
    2 posts
    Member since:
    May 2011

    Posted 30 Mar 2015 Link to this post

    I am trying event didSelectPoint in Swift with Telerik framework version Q1 2015 but it doesn't work. Neither this event in the solution TelerikUIExamplesInSwift. Could you double check that this event (or other similar events) works in Swift in Q1 2015. Many thanks.
  9. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 30 Mar 2015 Link to this post

    Hi Giang,

    Thank you for contacting us.

    I tried to reproduce the described issue in Swift with our latest release, but I couldn't. The didSelectPoint method is called only if the selectionMode property of your series is set to TKChartSelectionMode.DataPoint like in the code snippet below:
    series.selectionMode = TKChartSeriesSelectionMode.DataPoint

    Could you, please, confirm that the selection mode of your series is set to data point? 
    I am looking forward to your reply.

    Regards,
    Adrian
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
DevCraft banner