This is a migrated thread and some comments may be shown as answers.

TKChartSeries xaxis label color for selected Column

3 Answers 43 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Samer
Top achievements
Rank 1
Samer asked on 17 Dec 2015, 09:59 AM

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

3 Answers, 1 is accepted

Sort by
0
Yoanna
Telerik team
answered on 17 Dec 2015, 12:49 PM
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
0
Samer
Top achievements
Rank 1
answered on 27 Dec 2015, 08:07 AM

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

0
Sophi
Telerik team
answered on 28 Dec 2015, 10:03 PM
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
Tags
Chart
Asked by
Samer
Top achievements
Rank 1
Answers by
Yoanna
Telerik team
Samer
Top achievements
Rank 1
Sophi
Telerik team
Share this question
or