簡體   English   中英

設置CPTScatterPlot動畫以一次繪制一個點。 原點附加線

[英]Animating a CPTScatterPlot to draw one point at a time. Additional line to origin

我正嘗試為ScatterPlot制作動畫,如: 如何使用核心圖將動畫添加到散點圖?

但是我遇到了一個問題,即在零點處畫了一條額外的線。 這是我的問題的圖片:

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

我在Coreplot谷歌組上發現了該線程,描述了相同的問題: https ://groups.google.com/forum/#!searchin/coreplot-discuss/reloadDataInIndexRange/coreplot-discuss/ACpzO9neSsI/sgpv9UE4Xg0J

我嘗試實施此處描述的修復程序,但問題仍然存在。 這是我的代碼:

- (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;
}

這是我為圖形做的設置:

//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];

根據Eric的建議,我對方法-numberOfRecordsForPlot進行了修改:這樣它就不會返回大於要在任何時刻繪制的numberOfRecords的值。

_count這個詞令人困惑,它實際上應該像是'_index'之類的東西,實際上比count少一個。

這是我的最終方法

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM