Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Plot takes a long time to load
    primarykey
    data
    text
    <p>I have the following code in a method for setting up a CPTBarPlot:</p> <pre><code>CPTGraphHostingView *chartView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(10, 100, 290, 330)]; [self.view addSubview:chartView]; CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:chartView.bounds]; graph.plotAreaFrame.masksToBorder = NO; chartView.hostedGraph = graph; graph.paddingLeft = 20.0f; graph.paddingTop = 0.0f; graph.paddingRight = 0.0f; graph.paddingBottom = 20.0f; CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; textStyle.color = [CPTColor grayColor]; textStyle.fontName = @"Helvetica-Bold"; textStyle.fontSize = 8.0f;; CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle]; axisTitleStyle.color = [CPTColor grayColor]; axisTitleStyle.fontName = @"Helvetica-Bold"; axisTitleStyle.fontSize = 12.0f; CPTMutableLineStyle *axisLineStyleX = [CPTMutableLineStyle lineStyle]; axisLineStyleX.lineWidth = 2.0f; axisLineStyleX.lineColor = [CPTColor grayColor]; CPTMutableLineStyle *axisLineStyleY = [CPTMutableLineStyle lineStyle]; axisLineStyleY.lineWidth = 2.0f; axisLineStyleY.lineColor = [CPTColor grayColor]; CPTXYAxisSet *axisSet = (CPTXYAxisSet *) chartView.hostedGraph.axisSet; axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyFixedInterval; axisSet.xAxis.title = @"Ferientage pro Jahr"; axisSet.xAxis.titleTextStyle = axisTitleStyle; axisSet.xAxis.titleOffset = 10.0f; axisSet.xAxis.axisLineStyle = axisLineStyleX; axisSet.xAxis.labelTextStyle = textStyle; axisSet.xAxis.labelOffset = -7.0f; axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(10.0f); axisSet.xAxis.labelFormatter.maximumFractionDigits = 0; axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyNone; axisSet.yAxis.title = @"Bundesländer"; axisSet.yAxis.titleTextStyle = axisTitleStyle; axisSet.yAxis.titleOffset = 5.0f; axisSet.yAxis.axisLineStyle = axisLineStyleY; CPTXYPlotSpace *plotspace = (CPTXYPlotSpace *)graph.defaultPlotSpace; plotspace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(110)]; plotspace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(17)]; [graph addPlotSpace:plotspace]; CPTBarPlot *plot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor redColor] horizontalBars:YES]; plot.plotRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.5) length:CPTDecimalFromFloat(16)]; plot.labelTextStyle = textStyle; plot.labelFormatter.maximumFractionDigits = 0; plot.labelOffset = -3.0f; plot.identifier = @"bl"; plot.dataSource = self; plot.delegate = self; [graph addPlot:plot]; plot.anchorPoint = CGPointMake(0.0, 0.0); CABasicAnimation *scaling = [CABasicAnimation animationWithKeyPath:@"transform.scale.x"]; scaling.fromValue = [NSNumber numberWithFloat:0.0]; scaling.toValue = [NSNumber numberWithFloat:1.0]; scaling.duration = 1.0f; scaling.removedOnCompletion = NO; scaling.fillMode = kCAFillModeForwards; [plot addAnimation:scaling forKey:@"scaling"]; </code></pre> <p>Loading it takes about 4 seconds on an iPhone 5 and twice the time on an iPhone 4. Is that normal?</p> <p>I also tried to circumvent that by detaching that method from the main thread and using a<code>UIActivityIndicatorView</code>, however there's a second strange behavior:</p> <p>Sometimes it shows the spinner and the plot gets animated after a while, sometimes the spinner doesn't show up and the plot is displayed without an animation.</p> <p>So as you can see I'm actually struggling with two issues, but maybe the second one is intertwined with the first one.</p> <hr> <p>Maybe I show you other methods that are in conjunction with the Core Plot work:</p> <pre><code>-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot { return 16; } -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index { Ferien *ferien = [[Ferien alloc] init]; NSNumber *num = nil; if ([plot isKindOfClass:[CPTBarPlot class]]) { NSArray *reversedArrayCount = [[ferien.getToplist reverseObjectEnumerator] allObjects]; num = (NSNumber *)[NSNumber numberWithFloat:[[reversedArrayCount objectAtIndex:index] floatValue]]; } return num; </code></pre> <p>}</p> <pre><code>-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index { if ( [plot.identifier isEqual: @"bl"] ) { Ferien *ferien = [[Ferien alloc] init]; CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle]; textStyle.fontName = @"Helvetica-Bold"; textStyle.fontSize = 8.0f; textStyle.color = [CPTColor blackColor]; NSArray *reversedArrayBl = [[ferien.bundeslandListWithManagedObjects reverseObjectEnumerator] allObjects]; NSArray *reversedArrayCount = [[ferien.getToplist reverseObjectEnumerator] allObjects]; CPTTextLayer *label = [[CPTTextLayer alloc] initWithText:[NSString stringWithFormat:@"%@ (%@)", [reversedArrayBl objectAtIndex:index], [reversedArrayCount objectAtIndex:index]]]; label.textStyle = textStyle; return label; } CPTTextLayer *defaultLabel = [[CPTTextLayer alloc] initWithText:@"Label"]; return defaultLabel; </code></pre> <p>}</p> <pre><code>-(CPTFill *)barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index { if ([barPlot.identifier isEqual:@"bl"] ) { Ferien *ferien = [[Ferien alloc] init]; NSMutableArray *colors = [[NSMutableArray alloc] initWithObjects:[UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], [UIColor lightGrayColor], nil]; [colors replaceObjectAtIndex:15-ferien.currentBundesland withObject:[UIColor orangeColor]]; for (int i = 0; i &lt; 16; i++) { CPTGradient *gradient = [CPTGradient gradientWithBeginningColor:[colors objectAtIndex:index] endingColor:[CPTColor whiteColor] beginningPosition:0.0 endingPosition:1.5 ]; [gradient setGradientType:CPTGradientTypeAxial]; [gradient setAngle:320.0]; CPTFill *fill = [CPTFill fillWithGradient:gradient]; return fill; } } return [CPTFill fillWithColor:[CPTColor colorWithComponentRed:1.0 green:1.0 blue:1.0 alpha:1.0]]; </code></pre> <p>}</p> <pre><code>- (void)initView { self.labelFerienName.text = self.ferienName; self.labelFeriendauer.text = self.feriendauer; </code></pre> <p>}</p> <pre><code>- (void)mergeChanges:(NSNotification *)notification { AppDelegate *delegate = [[UIApplication sharedApplication] delegate]; NSManagedObjectContext *mainContext = [delegate managedObjectContext]; // Merge changes into the main context on the main thread [mainContext performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:notification waitUntilDone:YES]; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload