Get the CGPoint location in chart.frame of any bar

4 posts, 1 answers
  1. Miguel
    Miguel avatar
    7 posts
    Member since:
    Sep 2015

    Posted 23 Dec 2015 Link to this post

    Hi, 

    I need to draw a small image at the left of each horizontal bar outside of the chart. 

    To get a good align with the bars, I want to know the location of any bar in the chart.frame. (See the attached file).

    Who can I get it?

    Thanks!

  2. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 23 Dec 2015 Link to this post

    Hi Miguel,

    You can use the locationOfPoint method in TKChartSeriesRender class to get exact coordinates for each point in TKChart. Use the renderForSeries method in TKChartPlotView to get the series render. Here is an example:
    TKChartSeriesRender *render = [_chart.plotView renderForSeries:_chart.series[0]];
    CGPoint pt = [render locationOfPoint:_chart.series[0].items[1] inSeries:_chart.series[0]];
    NSLog(@"%f, %f", pt.x, pt.y);

    Please note that this method will return correct results only when TKChart is visible on screen. So, you can't call this method in viewDidLoad method. Use the viewDidAppear method instead.

    Feel free to contact us if you have further questions.

    Regards,
    Jack
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Miguel
    Miguel avatar
    7 posts
    Member since:
    Sep 2015

    Posted 23 Dec 2015 Link to this post

    Hi!, thank you

    But finally I do this:

    TKChartPlotView *plotView = _chart.subviews[1];
    CALayer *layerGrid = plotView.layer.sublayers.firstObject;
    _hGrid = layerGrid.frame.size.height;
    NSLog(@"frame: %@",NSStringFromCGRect(layerGrid.frame));
    _pntOgrid = [self.view convertPoint:CGPointZero fromView:plotView];
    NSLog(@"ptoOrigen: %@", NSStringFromCGPoint(_pntOgrid));
    //. . .

    Regards

  5. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 28 Dec 2015 Link to this post

    Hello, Miguel,

    Thank you for this update. I am glad to understand that the issue is solved.
    In case you need further assistance, do not hesitate to contact us.

    Regards,
    Adrian
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner