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

Chart Selection Problem in iPhone 6s & 6s+

3 Answers 21 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.
Miguel
Top achievements
Rank 1
Miguel asked on 20 Jan 2016, 09:31 AM

Hi, 

The chart selection of this simple example works ok in all iPhones models except in the new iPhones 6s & 6s+

How can I fix this issue? 

Thanks. 

001.//  ViewController.m
002.//  prSimpleChart                 V 202
003. 
004.#import "ViewController.h"
005. 
006.@implementation ViewController{
007.    TKChart *_chart;
008.    NSInteger _selectedIndex;
009.    NSArray *_arrValuesX;
010.    NSArray *_arrValuesBlue;
011.    NSArray *_arrValuesGray;
012.    NSNumber *_yMax, *_yMin;
013.}
014. 
015.- (void)viewDidLoad {
016.    [super viewDidLoad];
017.     
018.    _arrValuesX = @[@"L",@"M",@"X",@"J"];
019.    _arrValuesBlue = @[@40, @20, @30, @50];
020. 
021.    _chart = [[TKChart alloc] initWithFrame:CGRectMake(0, 80, [UIScreen mainScreen].bounds.size.width,
022.                                                       [UIScreen mainScreen].bounds.size.height / 2.0)];
023.    _chart.delegate = self;
024.    [self.view addSubview:_chart];
025.    [self updateChart];
026.}
027. 
028.-(void)updateChart{
029. 
030.    [_chart removeAllData];
031.    _selectedIndex = -1;
032.     
033.    // x Axis
034.    TKChartCategoryAxis *categoryAxis = [[TKChartCategoryAxis alloc] initWithCategories:_arrValuesX];
035.    _chart.xAxis = categoryAxis;
036.    _chart.xAxis.style.labelStyle.textColor = [UIColor grayColor];
037.    _chart.xAxis.style.labelStyle.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:11];
038.    _chart.xAxis.style.labelStyle.fitMode = TKChartAxisLabelFitModeNone;
039.    _chart.xAxis.style.lineHidden = NO;
040.    _chart.xAxis.style.lineStroke = [TKStroke strokeWithColor:[UIColor lightGrayColor] width:0.3];
041.    _chart.xAxis.style.majorTickStyle.ticksHidden = YES;
042.    _chart.xAxis.allowPan = YES;
043.     
044.    _yMax = @50;
045.    _yMin = @-50;
046.     
047.    // y Axis
048.    TKChartNumericAxis *yAxis = [[TKChartNumericAxis alloc] initWithMinimum:_yMin andMaximum:_yMax];
049.    yAxis.position = TKChartAxisPositionLeft;
050.    yAxis.style.lineHidden = YES;
051.    yAxis.style.majorTickStyle.ticksHidden = YES;
052.    yAxis.style.labelStyle.textColor = [UIColor grayColor];
053.    yAxis.style.labelStyle.font = _chart.xAxis.style.labelStyle.font;
054.    _chart.yAxis.allowPan = NO;
055.    [_chart addAxis:yAxis];
056.     
057.    // fill arrPnts Blue
058.    NSMutableArray *arrPntsBlue = [[NSMutableArray alloc] init];
059.    for (int i = 0; i < _arrValuesX.count; i++) {
060.        [arrPntsBlue addObject:[TKChartDataPoint dataPointWithX:_arrValuesX[i]
061.                                                              Y:_arrValuesBlue[i]]];
062. 
063.    }
064.    // Serie sB0 Columns
065.    TKChartColumnSeries *sB0 = [[TKChartColumnSeries alloc] initWithItems:arrPntsBlue];
066.    TKChartPaletteItem *palleteItemBlue = [[TKChartPaletteItem alloc] initWithFill:[TKSolidFill solidFillWithColor:[UIColor darkGrayColor]]];
067.    sB0.style.palette = [TKChartPalette new];
068.    [sB0.style.palette addPaletteItem:palleteItemBlue];
069.    sB0.selectionMode = TKChartSeriesSelectionModeDataPoint;
070.    [_chart addSeries:sB0];
071.     
072.    [_chart reloadData];
073.}
074. 
075.- (void)chart:(TKChart *)chart didSelectPoint:(id<TKChartData>)point inSeries:(TKChartSeries *)series atIndex:(NSInteger)index{
076.    NSLog(@"SEL: %zd",index);
077.    _selectedIndex = index;
078.}
079. 
080.-(void)chart:(TKChart *)chart didDeselectPoint:(id<TKChartData>)point inSeries:(TKChartSeries *)series atIndex:(NSInteger)index{
081.    NSLog(@"DES: %zd",index);
082.    _selectedIndex = -1;
083.}
084. 
085.- (TKChartPaletteItem *)chart:(TKChart *)chart paletteItemForSeries:(TKChartSeries *)series atIndex:(NSInteger)index{
086.    if (_selectedIndex == -1) {
087.        return nil;
088.    }
089.    TKChartPaletteItem *paletteItem = [TKChartPaletteItem new];
090.    if (_selectedIndex == index) {
091.        paletteItem.fill = [TKSolidFill solidFillWithColor:[UIColor darkGrayColor]];
092.    }
093.    else {
094.        paletteItem.fill = [TKSolidFill solidFillWithColor:[UIColor lightGrayColor]];
095.    }
096.    return paletteItem;
097.}
098. 
099.@end

3 Answers, 1 is accepted

Sort by
0
Yoanna
Telerik team
answered on 21 Jan 2016, 12:24 PM
Hello Miguel,

Thank you for contacting us.

I have tested the code out and it seems that having an axis explicitly set to TKChart is not a problem. 

I have noticed that you are using allowPan property without having the axis zoomed in, this properties are not supposed to be used this way. TKChart panning is designed to be used when zoom by one or more of the axes is done. In this case this is something that causes the issue. Removing this row _chart.xAxis.allowPan = YES;will fix the issue. However, I have noticed that when using zoom the selection is behaving strangely when used in iPhone 6s, 6s+ and I am investigating the issue further. You can track the status of the issue here, and contact us in case you have any further questions.


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
Miguel
Top achievements
Rank 1
answered on 21 Jan 2016, 05:17 PM

Hi, 
This example is extract from a project where the zoom and allowPan properties depend on quantity of points received. 
However, I have tested a similar code and the selection works ok in iPhones 6s & 6s+.
But, I found that don`t apply the color defined in …labelStyle.textColor.
What’s wrong? 
Thank you. 

01.-(void)updateChart{  // Change this method in the previous sample code with this one
02. 
03.    [_chart removeAllData];
04.    _selectedIndex = -1;
05.     
06.    // x Axis
07.    _chart.xAxis.style.labelStyle.textColor = [UIColor greenColor];
08.    _chart.xAxis.style.labelStyle.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:11];
09.    _chart.xAxis.style.lineHidden = NO;
10.    _chart.xAxis.style.lineStroke = [TKStroke strokeWithColor:[UIColor lightGrayColor] width:0.3];
11.    _chart.xAxis.style.majorTickStyle.ticksHidden = YES;
12.    _chart.xAxis.style.labelStyle.fitMode = TKChartAxisLabelFitModeNone;
13.    _chart.xAxis.allowPan = YES;
14. 
15.    _yMax = @50;
16.    _yMin = @-50;
17.     
18.    // y Axis
19.    _chart.yAxis.style.lineHidden = YES;
20.    _chart.yAxis.style.majorTickStyle.ticksHidden = YES;
21.    _chart.yAxis.style.labelStyle.textColor = [UIColor grayColor];
22.    _chart.yAxis.style.labelStyle.font = _chart.xAxis.style.labelStyle.font;
23.    _chart.yAxis.style.labelStyle.fitMode = TKChartAxisLabelFitModeNone;
24.    _chart.yAxis.allowPan = NO;
25.     
26.    // fill arrPnts Blue
27.    NSMutableArray *arrPntsBlue = [[NSMutableArray alloc] init];
28.    for (int i = 0; i < _arrValuesX.count; i++) {
29.        [arrPntsBlue addObject:[TKChartDataPoint dataPointWithX:_arrValuesX[i]
30.                                                              Y:_arrValuesBlue[i]]];
31.    }
32.     
33.    // Serie sB0 Columns
34.    TKChartColumnSeries *sB0 = [[TKChartColumnSeries alloc] initWithItems:arrPntsBlue];
35.    TKChartPaletteItem *palleteItemBlue = [[TKChartPaletteItem alloc] initWithFill:[TKSolidFill solidFillWithColor:[UIColor darkGrayColor]]];
36.    sB0.style.palette = [TKChartPalette new];
37.    [sB0.style.palette addPaletteItem:palleteItemBlue];
38.    sB0.selectionMode = TKChartSeriesSelectionModeDataPoint;
39.    [_chart addSeries:sB0];
40.     
41.    [_chart reloadData];
42.}

0
Yoanna
Telerik team
answered on 25 Jan 2016, 09:20 AM
Hello Miguel,

I have tested the described scenario, but the colors of the labels are applied properly and I couldn't find an issue with the textColor property in any conditions - with or without zoom/pan. 
If the issue persists, please send us a code snippet or a project where we can see the issue reproduced and investigate it further.

Looking forward to your reply.

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
Tags
Chart
Asked by
Miguel
Top achievements
Rank 1
Answers by
Yoanna
Telerik team
Miguel
Top achievements
Rank 1
Share this question
or