简体   繁体   English

设置CPTScatterPlot动画以一次绘制一个点。 原点附加线

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

I am trying to animate a ScatterPlot as described in: How to add animation to scatter graph using core plot? 我正尝试为ScatterPlot制作动画,如: 如何使用核心图将动画添加到散点图?

But I am encountering an issue where an additional line is drawn to the zero point. 但是我遇到了一个问题,即在零点处画了一条额外的线。 Here is an image of my problem: 这是我的问题的图片:

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

I found this thread on the Coreplot google group describing the same issue: https://groups.google.com/forum/#!searchin/coreplot-discuss/reloadDataInIndexRange/coreplot-discuss/ACpzO9neSsI/sgpv9UE4Xg0J 我在Coreplot谷歌组上发现了该线程,描述了相同的问题: https ://groups.google.com/forum/#!searchin/coreplot-discuss/reloadDataInIndexRange/coreplot-discuss/ACpzO9neSsI/sgpv9UE4Xg0J

I tried to implement the fix which was described there, but the issue persists. 我尝试实施此处描述的修复程序,但问题仍然存在。 Here is my code: 这是我的代码:

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

This is the setup I do for the graph: 这是我为图形做的设置:

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

Using Eric's suggestion I adapted my method -numberOfRecordsForPlot: so that it didn't return a value which was any greater than the numberOfRecords to be plotted at any instant. 根据Eric的建议,我对方法-numberOfRecordsForPlot进行了修改:这样它就不会返回大于要在任何时刻绘制的numberOfRecords的值。

The word _count is confusing, it should really be something like '_index' which is actually one less than count. _count这个词令人困惑,它实际上应该像是'_index'之类的东西,实际上比count少一个。

Here is my final method 这是我的最终方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM