TKChartSeries xaxis label color for selected Column

4 posts, 0 answers
  1. Samer
    Samer avatar
    3 posts
    Member since:
    May 2014

    Posted 17 Dec 2015 Link to this post

    Hello,

     I need to change the color of the label for selected bar. How can I do this ?

     Which delegate will get called for it ?

    Screenshot is attached.

    Thanks in Advance

     

    Sohrab Hussain
  2. Yoanna
    Admin
    Yoanna avatar
    44 posts

    Posted 17 Dec 2015 Link to this post

    Hello Samer, 

    Thank you for contacting us.

    You can apply color to the label of the selected bar by using the didSelectPoint:inSeries:atIndex and attribudetTextForAxis:value:atIndex methods of TKChartDelegate

    In the first one you will get the index of the selected point and you will call TKChart to reload, so the color of the label could be updated:
    -(void)chart:(TKChart *)chart didSelectPoint:(id<TKChartData>)point inSeries:(TKChartSeries *)series atIndex:(NSInteger)index
    {
        sel = index;
        [_chart reloadData];
    }

    In the second method you should pass an attributed string to be placed at the desired index:
    -(NSAttributedString *)chart:(TKChart *)chart attributedTextForAxis:(TKChartAxis *)axis value:(id)value atIndex:(NSUInteger)index
    {
        NSAttributedString *attrStr;
        if(axis == _chart.xAxis) {
             
            if(index == sel) {
            NSString *string = [NSString stringWithFormat:@"%@", value];
            NSDictionary *attrs = @{ NSForegroundColorAttributeName : [UIColor redColor] };
            attrStr = [[NSAttributedString alloc] initWithString:string attributes:attrs];
            }
        }
         
        return attrStr;
    }


    I hope this points you in the right direction. If you have further questions do not hesitate to contact us.
    Regards,
    Yoanna
    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. Samer
    Samer avatar
    3 posts
    Member since:
    May 2014

    Posted 27 Dec 2015 in reply to Yoanna Link to this post

    Thanks for the response.

     But while doing as suggested, the method is not getting called while reloading data.

    -(NSAttributedString *)chart:(TKChart *)chart attributedTextForAxis:(TKChartAxis *)axis value:(id)value atIndex:(NSUInteger)index

  5. Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 28 Dec 2015 Link to this post

    Hi Samer,

    I tried to reproduce the explained behavior but everything seems to work fine.
    The method chart:attributedTextForAxis:value:atIndex: gets called for every data point label every time the chart is being reloaded, just as expected.
    Could you please be more specific on the issue or maybe send us a code sample demonstrating it, so we can investigate and provide you with proper solution.

    Looking forward to hearing from you.

    Regards,
    Sophi
    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