Menganimasikan CPTScatterPlot untuk menggambar satu titik pada satu waktu. Jalur tambahan ke asal

Saya mencoba menganimasikan ScatterPlot seperti yang dijelaskan dalam: Bagaimana menambahkan animasi ke grafik sebar menggunakan plot inti?

Namun saya mengalami masalah ketika garis tambahan ditarik ke titik nol. Berikut ini gambar masalah saya:

https://i.stack.imgur.com/OizxH.png

Saya menemukan utas ini di grup Google Coreplot yang menjelaskan masalah yang sama: https://groups.google.com/forum/#!searchin/coreplot-discuss/reloadDataInIndexRange/coreplot-discuss/ACpzO9neSsI/sgpv9UE4Xg0J

Saya mencoba menerapkan perbaikan yang dijelaskan di sana, namun masalahnya tetap ada. Ini kode saya:

- (void) updateData
{
    _count = 0;
    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(animateGraph:) userInfo:nil repeats:YES];
}

- (void)animateGraph:(NSTimer *)timer
{
    if (_count < PREDICT_MINUTES) {
        [[self.graph plotWithIdentifier:@"estimatedBGPlot"] reloadDataInIndexRange:NSMakeRange(_count, 1)];
    } else {
        [timer invalidate];
    }
    _count += 1;
}

Ini adalah pengaturan yang saya lakukan untuk grafik:

//Make the boundaries of the graph and hosting view the size of the containing view.
self.graph = [[CPTXYGraph alloc] initWithFrame:CGRectMake(0, 0, 320, 250)];
CPTGraphHostingView *hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 0, 320, 250)];
[self.view addSubview:hostingView];

hostingView.hostedGraph = self.graph;
hostingView.collapsesLayers = NO;

//Pad the plot area. This ensures that the tick marks and labels
//will show up as is appropriate.
self.graph.plotAreaFrame.paddingBottom = 30.0;
self.graph.paddingBottom = 0.0;
self.graph.paddingTop = 0.0;
self.graph.paddingLeft = 0.0;
self.graph.paddingRight = 0.0;

//This is shared by all graphs in the plotSpace.
//It sets the coordinates of the axes
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
                                                length:CPTDecimalFromFloat(PREDICT_MINUTES)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) length:CPTDecimalFromFloat(300)];

CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
CPTXYAxis *y = axisSet.yAxis;
x.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0);
y.orthogonalCoordinateDecimal = CPTDecimalFromFloat(0);

CPTMutableLineStyle *clearStyle = [CPTMutableLineStyle lineStyle];
clearStyle.lineColor = [CPTColor clearColor];

CPTMutableLineStyle *thickWhiteStyle = [CPTMutableLineStyle lineStyle];
thickWhiteStyle.lineColor = [CPTColor whiteColor];
thickWhiteStyle.lineWidth = 2.0f;

x.majorIntervalLength = [[NSNumber numberWithInt:30] decimalValue];
x.minorTicksPerInterval = 1;
x.majorTickLineStyle = thickWhiteStyle;
x.minorTickLineStyle = clearStyle;
x.axisLineStyle = clearStyle;
x.minorTickLength = 5.0f;
x.majorTickLength = 7.0f;
x.labelOffset = 3.0f;

x.labelingPolicy = CPTAxisLabelingPolicyNone;
CPTScatterPlot* estimatedBGPlot = [[CPTScatterPlot alloc] initWithFrame:self.graph.defaultPlotSpace.accessibilityFrame];
estimatedBGPlot.identifier = @"estimatedBGPlot";
estimatedBGPlot.interpolation = CPTScatterPlotInterpolationCurved;
CPTMutableLineStyle *ls1 = [CPTMutableLineStyle lineStyle];
ls1.lineWidth = 4.0f;
ls1.lineColor = [CPTColor whiteColor];
estimatedBGPlot.dataLineStyle = ls1;
estimatedBGPlot.dataSource = self;
[self.graph addPlot:estimatedBGPlot];

CPTScatterPlot* predictPlot = [[CPTScatterPlot alloc] initWithFrame:self.graph.defaultPlotSpace.accessibilityFrame];
predictPlot.identifier = @"predictPlot";
predictPlot.interpolation = CPTScatterPlotInterpolationCurved;
CPTMutableLineStyle *ls2 = [CPTMutableLineStyle lineStyle];
ls2.lineWidth = 3.0f;
ls2.lineColor = [CPTColor greenColor];
ls2.dashPattern=[NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:5],[NSDecimalNumber numberWithInt:5],nil];
predictPlot.dataLineStyle = ls2;
predictPlot.dataSource = self;
[self.graph addPlot:predictPlot];

person user3030055    schedule 25.11.2013    source sumber
comment
Nilai apa yang dikembalikan dari -numberOfRecordsForPlot:? Apakah ia pernah mengembalikan nilai lebih besar dari _count?   -  person Eric Skroch    schedule 26.11.2013
comment
Ya, numberOfRecordsForPlot selalu lebih besar dari _count. Saya mencoba membuat grafik sebagian dari poin yang tersedia. NumberOfRecordsForPlot mengembalikan 580 ketika saya NSLog, sementara _count terus bertambah hingga 180. Rentang x pada grafik adalah dari 0 hingga 180. Saya berharap dapat memperluas rentang ini jika pengguna menggeser ke kiri. Hingga akhirnya mencapai 580. Namun untuk saat ini saya hanya membuat grafik 180 nilai pertama.   -  person user3030055    schedule 26.11.2013


Jawaban (1)


Dengan menggunakan saran Eric, saya mengadaptasi metode saya -numberOfRecordsForPlot: sehingga tidak mengembalikan nilai yang lebih besar dari numberOfRecords yang akan diplot kapan saja.

Kata _count membingungkan, seharusnya seperti '_index' yang sebenarnya kurang dari satu count.

Inilah metode terakhir saya

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
    return _count + 1;
}
person user3030055    schedule 26.11.2013