Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c CorePlot图形计算器不在(0;0)点启动_Objective C_Cocoa_Core Plot - Fatal编程技术网

Objective c CorePlot图形计算器不在(0;0)点启动

Objective c CorePlot图形计算器不在(0;0)点启动,objective-c,cocoa,core-plot,Objective C,Cocoa,Core Plot,我的应用程序中有一个用CorePlot编写的图形计算器插件。还有一个小错误——当图形出现在屏幕上时,屏幕中央的点(0;0)将显示靠近(2;3)的点 代码如下: -(void)viewDidLoad { [super viewDidLoad]; graph = [[CPXYGraph alloc] initWithFrame:CGRectZero]; CPTheme *theme = [CPTheme themeNamed:kCPStocksTheme]; [

我的应用程序中有一个用CorePlot编写的图形计算器插件。还有一个小错误——当图形出现在屏幕上时,屏幕中央的点(0;0)将显示靠近(2;3)的点

代码如下:

-(void)viewDidLoad 
{

    [super viewDidLoad];

    graph = [[CPXYGraph alloc] initWithFrame:CGRectZero];
    CPTheme *theme = [CPTheme themeNamed:kCPStocksTheme];
    [graph applyTheme:theme];
    CPGraphHostingView *hostingView = (CPGraphHostingView *)self.view ;
    hostingView.hostedGraph = graph;

    graph.paddingLeft =5;
    graph.paddingTop = 5;
    graph.paddingRight = 5;
    graph.paddingBottom = 5;

    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.allowsUserInteraction = YES;
    PlotSpaceX=2;
    PlotSpaceY=3;
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.0)    length:CPDecimalFromFloat(PlotSpaceX)];
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.0)    length:CPDecimalFromFloat(PlotSpaceY)];

    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
    CPXYAxis *x = axisSet.xAxis;
    x.majorIntervalLength = CPDecimalFromString(@"0.5");
    x.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");
    x.minorTicksPerInterval = 2;

    CPXYAxis *y = axisSet.yAxis;
    y.majorIntervalLength = CPDecimalFromString(@"0.5");
    y.minorTicksPerInterval = 2;
    y.orthogonalCoordinateDecimal = CPDecimalFromString(@"0");

    boundLinePlot =  [[[CPScatterPlot alloc] init] autorelease];
    boundLinePlot.identifier = @"Blue Plot";
    boundLinePlot.dataLineStyle.miterLimit = 1.0f;
    boundLinePlot.dataLineStyle.lineWidth = 3.0f;
    boundLinePlot.dataLineStyle.lineColor = [CPColor redColor];
    boundLinePlot.dataSource = self;
    [graph addPlot:boundLinePlot];

    NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100000];
    NSUInteger i;
    for ( i = 0; i < 600000; i++ ) {
        id x = [NSNumber numberWithFloat:i*0.05-1000];
        id y =[NSNumber numberWithFloat: [x floatValue] *[x floatValue]];
        [contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
    }
    self.dataForPlot = contentArray;

}


#pragma mark -
#pragma mark Plot Data Source Methods

-(NSUInteger)numberOfRecordsForPlot:(CPPlot *)plot {
    return [dataForPlot count];
}

-(NSNumber *)numberForPlot:(CPPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{
    NSNumber *num = [[dataForPlot objectAtIndex:index] valueForKey:(fieldEnum == CPScatterPlotFieldX ? @"x" : @"y")];

    return num;
}
-(void)viewDidLoad
{
[超级视图下载];
graph=[[CPXYGraph alloc]initWithFrame:CGRectZero];
CPTheme*theme=[CPTheme主题名:KCPStocksTime];
[图形应用主题:主题];
CPGraphHostingView*hostingView=(CPGraphHostingView*)self.view;
hostingView.hostedGraph=图形;
graph.paddingLeft=5;
graph.paddingTop=5;
graph.paddingRight=5;
graph.paddingBottom=5;
CPXYPlotSpace*plotSpace=(CPXYPlotSpace*)graph.defaultPlotSpace;
plotSpace.allowUserInteraction=是;
PlotSpaceX=2;
PlotSpaceY=3;
plotSpace.xRange=[CPPlotRange plotRangeWithLocation:cpdecimalfloat(1.0)长度:cpdecimalfloat(PlotSpaceX)];
plotSpace.yRange=[CPPlotRange plotRangeWithLocation:cpdecimalfloat(1.0)长度:cpdecimalfloat(PlotSpaceY)];
CPXYAxisSet*axisSet=(CPXYAxisSet*)graph.axisSet;
CPXYAxis*x=axisSet.xAxis;
x、 majorIntervalLength=CPDecimalFromString(@“0.5”);
x、 正交坐标CIMAL=CPDecimalFromString(@“0”);
x、 minorTicksPerInterval=2;
CPXYAxis*y=axisSet.yAxis;
y、 majorIntervalLength=CPDecimalFromString(@“0.5”);
y、 minorTicksPerInterval=2;
y、 正交坐标CIMAL=CPDecimalFromString(@“0”);
boundLinePlot=[[CPScatterPlot alloc]init]自动释放];
boundLinePlot.identifier=@“蓝色绘图”;
boundLinePlot.dataLineStyle.miterLimit=1.0f;
boundLinePlot.dataLineStyle.lineWidth=3.0f;
boundLinePlot.dataLineStyle.lineColor=[CPColor redColor];
boundLinePlot.dataSource=self;
[图形添加图:边界线图];
NSMutableArray*contentArray=[NSMutableArray阵列容量:100000];
NSUI;
对于(i=0;i<600000;i++){
id x=[NSNumber numberWithFloat:i*0.05-1000];
id y=[NSNumber numberWithFloat:[x floatValue]*[x floatValue]];
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x,@“x”,y,@“y”,nil];
}
self.dataForPlot=contentArray;
}
#布拉格标记-
#pragma标记图数据源方法
-(NSUInteger)numberOfRecordsForPlot:(Cplot*)绘图{
返回[dataForPlot count];
}
-(NSNumber*)numberForPlot:(CPPlot*)绘图字段:(NSInteger)字段枚举记录索引:(NSInteger)索引
{
NSNumber*num=[[dataForPlot objectAtIndex:index]valueForKey:(fieldEnum==CPScatterPlotFieldX?@“x”:@“y”);
返回num;
}

如何修复它,使点(0;0)在加载图形时出现?

如前所述,您的中心点应为(2,2.5)

绘图范围作为起始位置和长度给出。X范围从1到(1+2)=3,Y范围从1到(1+3)=4。试着这样做:

plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-PlotSpaceX) length:CPDecimalFromFloat(PlotSpaceX * 2.0)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-PlotSpaceY) length:CPDecimalFromFloat(PlotSpaceY * 2.0)];