This question is locked. New answers and comments are not allowed.
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
0
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:
In the second method you should pass an attributed string to be placed at the desired index:
I hope this points you in the right direction. If you have further questions do not hesitate to contact us.
Regards,
Yoanna
Telerik
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)index0
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
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