Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get my Linechart to work since Xcode 8 update #1640

Closed
ericjsalazar opened this issue Oct 10, 2016 · 2 comments
Closed

Cannot get my Linechart to work since Xcode 8 update #1640

ericjsalazar opened this issue Oct 10, 2016 · 2 comments

Comments

@ericjsalazar
Copy link

Greetings all,

I've searched every issue and the documentation and cannot seem to get my code to work. I was wondering if you guys could help me fix my issue as described below.

First of all, with the change of formatters, I cannot get it to work. Here's an example of what I had:
screen shot 2016-10-10 at 2 35 17 pm

The old code (short version) consisted of:

    SPRangeFormatter *rangeFormatter = (SPRangeFormatter *)leftAxis.valueFormatter;
    if (!rangeFormatter) {
        rangeFormatter = [[SPRangeFormatter alloc] init];
    }
    rangeFormatter.resultsDict = uniquePresentationResults;

    leftAxis.valueFormatter = rangeFormatter;
    NSString *resultOrder = [resultDict objectForKey:@"sortOrder"];
    [yVals addObject:[[ChartDataEntry alloc] initWithValue:[resultOrder intValue] - 1 xIndex:i]];
        }
    LineChartDataSet *set1 = [[LineChartDataSet alloc] initWithYVals:yVals label:[parameterName capitalizedString]];

Where SPRangeFormatter is defined in its own class with a setter method:

- (void)setResultsDict:(NSDictionary *)resultsDict
{
    _resultsDict = resultsDict;

    if (!self.sortedResults) {
        self.sortedResults = [[NSMutableArray alloc] init];
    }
    [self.sortedResults removeAllObjects];

    [self.sortedResults addObjectsFromArray:[_resultsDict allValues]];
    NSSortDescriptor *sortOrderDescriptor = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
    [self.sortedResults sortUsingDescriptors:@[sortOrderDescriptor]];
}

With the update, I've changed the code to the following:

    SPRangeFormatter *rangeFormatter = (SPRangeFormatter *)leftAxis.valueFormatter;
    if (!rangeFormatter) {
        rangeFormatter = [[SPRangeFormatter alloc] init];
    }
    NSLog(@"Results: %@", uniquePresentationResults);
    rangeFormatter.paramResultsDict = uniquePresentationResults;
    leftAxis.valueFormatter = [[ChartDefaultAxisValueFormatter alloc] initWithFormatter: rangeFormatter];
    NSString *resultOrder = [resultDict objectForKey:@"sortOrder"];
    int resultValue = [resultOrder intValue];
    if (resultOrder) {
        [allMutableVals addObject:[[ChartDataEntry alloc] initWithX:i y:resultValue]];
    }

When I build, I get the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChartDefaultAxisValueFormatter setParamResultsDict:]: unrecognized selector sent to instance 0x15e2015b0'

If I comment out the formatter, the points I pass through will not be displayed on the graph and I get the following error:
: Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API and this value is being ignored.Please fix this problem.

@danielgindi
Copy link
Collaborator

Why SPRangeFormatter *rangeFormatter = (SPRangeFormatter *)leftAxis.valueFormatter;?
If you haven't set leftAxis.valueFormatter to be an SPRangeFormatter, then it won't return a SPRangeFormatter.
So your call to .paramResultsDict results in "unrecognized selector sent to instance ".

Have you read the migration notes (#1474)?
You have three options: Either create a ChartDefaultAxisValueFormatter and pass it your old formatter, subclass ChartDefaultAxisValueFormatter, or make SPRangeFormatter conform to the IAxisValueFormatter protocol and pass it to leftAxis.valueFormatter.

@ericjsalazar
Copy link
Author

Thank you daniel. I've been struggling since the update and tried to resist asking until I had no other options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants