2014-02-25 2 views
1

저는 iPhone 용 Stackoverflow 및 Xcode의 초보자입니다. 영어가 모국어가 아니므로 나와 함께하시기 바랍니다. 날짜 (x 축)와 연료 절약 값 (y 축) 사이의 그래프를 만들려고했습니다.iPhone 데이터 용 Xcode가있는 scatterplot이 축과 동기화되지 않고 두꺼운 두께가 표시되지 않습니다.

코어 플롯 1.4를 사용하고 있습니다. 내 문제는 :

  1. 데이터가 어떻게 든 x 축에 직접 동기화되지 않습니다.
  2. 어떻게 든 주요 체크리스트가 표시되지 않습니다. (해결됨)
  3. 그래프에 positif 축만 표시되도록 할 방법이 있습니까? (해결)

데이터를 디버깅하기 위해 NSLog를 많이 사용했습니다. 나는 사용자 레이블을 사용하는 방법 및 분산 형 그래프를 만드는 방법에 대한 자습서를 위해이 사이트를 포함하여 Google 검색을 수행했습니다.

(
    { 
    0 = "31-Jan-2014"; 
    1 = 10; 
}, 
    { 
    0 = "02-Feb-2014"; 
    1 = "10.07"; 
}, 
    { 
    0 = "24-Feb-2014"; 
    1 = "8.75"; 
} 
) 

나는 위의 데이터와 함께 이상한 결과를 가지고 :

나는 다음과 같은 데이터가 있습니다. 이 내 그래프의 픽처에 포함 된 그래프 참조하세요

Screenshot

이 그래프에서, Y 데이터는 X 축에 매핑되지 않는다.

여기에 ID x 및 ID y를 데이터

다음
2014-02-25 16:09:01.855 Fuel Eco[12079:70b] x is : 31-Jan-2014 
2014-02-25 16:09:01.855 Fuel Eco[12079:70b] y is : 10 
2014-02-25 16:09:01.855 Fuel Eco[12079:70b] int X is 0 
2014-02-25 16:09:01.856 Fuel Eco[12079:70b] int Y is 1 
2014-02-25 16:09:01.856 Fuel Eco[12079:70b] ScatterPlotField X is 0 
2014-02-25 16:09:01.856 Fuel Eco[12079:70b] ScatterPlotField Y is 1 
2014-02-25 16:09:01.857 Fuel Eco[12079:70b] Data to be Plotted: (
     { 
     0 = "31-Jan-2014"; 
     1 = 10; 
    } 
) 
2014-02-25 16:09:01.857 Fuel Eco[12079:70b] x is : 02-Feb-2014 
2014-02-25 16:09:01.857 Fuel Eco[12079:70b] y is : 10.07 
2014-02-25 16:09:01.858 Fuel Eco[12079:70b] int X is 0 
2014-02-25 16:09:01.858 Fuel Eco[12079:70b] int Y is 1 
2014-02-25 16:09:01.858 Fuel Eco[12079:70b] ScatterPlotField X is 0 
2014-02-25 16:09:01.859 Fuel Eco[12079:70b] ScatterPlotField Y is 1 
2014-02-25 16:09:01.859 Fuel Eco[12079:70b] Data to be Plotted: (
     { 
     0 = "31-Jan-2014"; 
     1 = 10; 
    }, 
     { 
     0 = "02-Feb-2014"; 
     1 = "10.07"; 
    } 
) 
2014-02-25 16:09:01.859 Fuel Eco[12079:70b] x is : 24-Feb-2014 
2014-02-25 16:09:01.860 Fuel Eco[12079:70b] y is : 8.75 
2014-02-25 16:09:01.860 Fuel Eco[12079:70b] int X is 0 
2014-02-25 16:09:01.860 Fuel Eco[12079:70b] int Y is 1 
2014-02-25 16:09:01.861 Fuel Eco[12079:70b] ScatterPlotField X is 0 
2014-02-25 16:09:01.861 Fuel Eco[12079:70b] ScatterPlotField Y is 1 
2014-02-25 16:09:01.861 Fuel Eco[12079:70b] Data to be Plotted: (
     { 
     0 = "31-Jan-2014"; 
     1 = 10; 
    }, 
     { 
     0 = "02-Feb-2014"; 
     1 = "10.07"; 
    }, 
     { 
     0 = "24-Feb-2014"; 
     1 = "8.75"; 
    } 
) 

에 대한 nslog의 결과는 "결과를 보여주기 위해 관련 코드

- (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot 
{ 
    NSLog(@"Number of Records for Plot = %lu",(unsigned long)[self.plotData count]); 
    return [_plotData count]; 
} 

- (NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx 
{ 
    //NSDecimalNumber *result = [[_plotData objectAtIndex:idx]objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
    NSNumber *result; 
     switch (fieldEnum) { 
     case CPTScatterPlotFieldX: 
//    NSDate * observationDate = [[_plotData objectAtIndex:idx]objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
//    NSTimeInterval secondsSince1970 = [_observationDate timeIntervalSince1970]; 
       result = [[_plotData objectAtIndex:idx]objectForKey:[NSNumber numberWithInt:fieldEnum]]; 

      break; 
     case CPTScatterPlotFieldY: 
      result = [[_plotData objectAtIndex:idx] objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
} 

//result = [[_plotData objectAtIndex:idx] objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
    NSLog(@"Number tobe Plot with index = %@ %lu, %lu",result,(unsigned long)idx,(unsigned long)fieldEnum); 
    return result; 

} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self initPlot]; 



    // Do any additional setup after loading the view. 
} 

- (void)initPlot 
{ 
    //NSDate *refDate  = [NSDate dateWithNaturalLanguageString:@"12:00 Oct 29, 2009"]; 
    [self fetchResultOneWeek]; 
    [self configureHost]; 
    [self configureFEGraph]; 
    [self configurePlots]; 
    [self configureAxis]; 
} 

- (void)configureHost 
{ 
    CGRect frame1 = CGRectMake(0,80,320,200); 
    FESubView = [[CPTGraphHostingView alloc]initWithFrame:frame1]; 
    FESubView.allowPinchScaling = YES; 
    [self.view addSubview:FESubView]; 
    CGRect frame2 = CGRectMake(0,410,320,400); 
    GasPriceSubView = [[CPTGraphHostingView alloc]initWithFrame:frame2]; 
    GasPriceSubView.allowPinchScaling = YES; 
    [self.view addSubview:GasPriceSubView]; 
} 

- (void)configureFEGraph 
{ 
    CPTGraph *graph = [[CPTXYGraph alloc]initWithFrame:FESubView.bounds]; 
    [graph applyTheme:[CPTTheme themeNamed:kCPTStocksTheme]]; 
    FESubView.hostedGraph = graph; 

    graph.title = @"Fuel Economy Graph"; 
    CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle]; 
    titleStyle.color = [CPTColor whiteColor]; 
    titleStyle.fontName = @"Helvetica-Bold"; 
    titleStyle.fontSize = 14.0f; 
    graph.titleTextStyle = titleStyle; 
    graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop; 
    graph.titleDisplacement = CGPointMake(0.0f, 10.0f); 

    // 4 - Set padding for plot area 
    [graph.plotAreaFrame setPaddingLeft:10.0f]; 
    [graph.plotAreaFrame setPaddingBottom:10.0f]; 
    [graph.plotAreaFrame setPaddingTop:10.0f]; 
    [graph.plotAreaFrame setPaddingRight:10.0f]; 

    // 5 - Enable user interactions for plot space 
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace; 
    plotSpace.allowsUserInteraction = YES; 

} 

- (void)configurePlots 
{ 
    NSMutableArray *dataTobePlotted = [NSMutableArray array]; 

    NSUInteger i; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
    [dateFormatter setDateFormat:@"dd-MMM-YYY"]; 
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0:07"]]; 
    //NSTimeInterval oneDay = 24 * 60 * 60; 

    for (i = 0;i < [[self.fullTransaction valueForKey:@"tDate"]count]; i++) 
    { 
     NSDate *observationDate = [[self.fullTransaction valueForKey:@"tDate"]objectAtIndex:i]; 
     NSLog(@"observationDate is : %@",observationDate); 
     NSTimeInterval x = [observationDate timeIntervalSince1970]; 
     NSLog(@"x is : %f",x); 
     id y = [[self.fullTransaction valueForKey:@"tFuelEconomy"]objectAtIndex:i]; 
     NSLog(@"y is : %@",y); 
     [dataTobePlotted addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithDouble:x],[NSNumber numberWithInt:CPTScatterPlotFieldX],y,[NSNumber numberWithInt:CPTScatterPlotFieldY],nil]]; 
     //[dataTobePlotted addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSDecimalNumber numberWithFloat:x],[NSNumber numberWithInt:CPTScatterPlotFieldX],y,[NSNumber numberWithInt:CPTScatterPlotFieldY],nil]]; 
     NSLog(@" int X is %@",[NSNumber numberWithInt:CPTScatterPlotFieldX]); 
     NSLog(@" int Y is %@",[NSNumber numberWithInt:CPTScatterPlotFieldY]); 
     NSLog(@"ScatterPlotField X is %@",[NSNumber numberWithInt:CPTScatterPlotFieldX]); 
     NSLog(@"ScatterPlotField Y is %@",[NSNumber numberWithInt:CPTScatterPlotFieldY]); 
     NSLog(@"Data to be Plotted: %@",dataTobePlotted); 
    } 
    self.plotData = dataTobePlotted; 

    CPTGraph *graph = FESubView.hostedGraph; 
    [graph applyTheme:[CPTTheme themeNamed:kCPTStocksTheme]]; 

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
     //create plot 
    CPTScatterPlot *fePlot = [[CPTScatterPlot alloc]init]; 
    fePlot.dataSource = self; 
    CPTColor *feColor = [CPTColor greenColor]; 
    [graph addPlot:fePlot]; 

    //setup plot space 
    [plotSpace scaleToFitPlots:[NSArray arrayWithObjects: fePlot,Nil]]; 
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"3.0") length:CPTDecimalFromString(@"10.0")]; 
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"8.0") length:CPTDecimalFromString(@"2.0")]; 

    //set up plot space 
    //[plotSpace scaleToFitPlots:[NSArray arrayWithObjects:fePlot,nil]]; 
    CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy]; 
    [xRange expandRangeByFactor:CPTDecimalFromCGFloat(2.0f)]; 
    plotSpace.xRange = xRange; 
    CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy]; 
    [yRange expandRangeByFactor:CPTDecimalFromCGFloat(5.0f)]; 
    plotSpace.yRange = yRange; 


// //create styles and symbols 
    CPTMutableLineStyle *feLineStyle = [fePlot.dataLineStyle mutableCopy]; 
    CPTColor *areaColor = [CPTColor colorWithComponentRed:0.3 green:1.0 blue:0.3 alpha:0.3]; 
    CPTGradient *areaGradient = [CPTGradient gradientWithBeginningColor:areaColor endingColor:[CPTColor clearColor]]; 
    areaGradient.angle = -90.0f; 
    CPTFill *areaGradientFill = [CPTFill fillWithGradient:areaGradient]; 
    fePlot.areaFill = areaGradientFill; 

    feLineStyle.lineWidth = 2.5; 
    feLineStyle.lineColor = feColor; 
    fePlot.dataLineStyle = feLineStyle; 
    CPTMutableLineStyle *feSymbolLineStyle = [CPTMutableLineStyle lineStyle]; 
    feSymbolLineStyle.lineColor = feColor; 
    CPTPlotSymbol *feSymbol = [CPTPlotSymbol ellipsePlotSymbol]; 
    feSymbol.fill = [CPTFill fillWithColor:feColor]; 
    feSymbol.lineStyle = feSymbolLineStyle; 
    feSymbol.size = CGSizeMake(6.0f, 6.0f); 
    fePlot.plotSymbol = feSymbol; 
} 


- (void)configureAxis 
{ 
    // 1 - Create styles 
     // 2 - Get axis set 
    CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle]; 
    axisTitleStyle.color = [CPTColor whiteColor]; 
    axisTitleStyle.fontName = @"Helvetica-Bold"; 
    axisTitleStyle.fontSize = 12.0f; 
    CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle]; 
    axisLineStyle.lineWidth = 2.0f; 
    axisLineStyle.lineColor = [CPTColor whiteColor]; 
    CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init]; 
    axisTextStyle.color = [CPTColor whiteColor]; 
    axisTextStyle.fontName = @"Helvetica-Bold"; 
    axisTextStyle.fontSize = 11.0f; 
    CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle]; 
    tickLineStyle.lineColor = [CPTColor whiteColor]; 
    tickLineStyle.lineWidth = 2.0f; 
    CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle]; 
    tickLineStyle.lineColor = [CPTColor blackColor]; 
    tickLineStyle.lineWidth = 1.0f; 
    CPTMutableTextStyle *labelXTextStyle = [CPTMutableTextStyle textStyle]; 
    labelXTextStyle.fontName = @"Helvetica"; 
    labelXTextStyle.fontSize = 10; 
    labelXTextStyle.color = [CPTColor whiteColor]; 

    // 2 - Get Axis Set 
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *) FESubView.hostedGraph.axisSet; 

    // 3 Configure x-Axis 
    CPTXYAxis *x   = axisSet.xAxis; 
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"4"); 
    x.title = @"Date"; 
    x.titleTextStyle = axisTitleStyle; 
    x.titleOffset = 47.0f; 
    //x.title = @"Date"; 
    x.minorTicksPerInterval  = 0; 
    x.majorTickLength = 10.0f; 
    x.tickDirection = CPTSignPositive; 

    //NSArray *customTickLocations = [NSArray arrayWithObjects:[NSDecimalNumber numberWithInt:5], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:10], [NSDecimalNumber numberWithInt:15], 
    //        [NSDecimalNumber numberWithInt:20], [NSDecimalNumber numberWithInt:25],[NSDecimalNumber numberWithInt:30],nil]; 

    NSInteger i; 
    NSMutableArray *customTickLocations = [NSMutableArray array]; 
    for (i = 0; i < [[self.fullTransaction valueForKey:@"tDate"]count];i++) 
    { 
     [customTickLocations addObject:[NSDecimalNumber numberWithInt:((i+1)*5)]]; 
    } 

    CPTPlotRange *xAxisRange=[CPTPlotRange plotRangeWithLocation:CPTDecimalFromString(@"0.0") length:CPTDecimalFromString(@"24.0")]; 
     x.visibleRange=xAxisRange; 

    NSLog(@"dates are %@", [self.fullTransaction valueForKey:@"tDate"]); 
    NSLog(@"Transaction FE %@", [self.fullTransaction valueForKey:@"tFuelEconomy"]); 
    NSMutableArray *customLabels = [NSMutableArray arrayWithCapacity:[self.plotData count]]; 
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
    [dateFormatter setDateFormat:@"dd-MMM-YYY"]; 
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT+0:07"]]; 
    NSMutableSet *xLocations = [NSMutableSet setWithCapacity:[[self.fullTransaction valueForKey:@"tDate"]count]]; 
    x.labelingPolicy=CPTAxisLabelingPolicyNone; 
    x.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"1"] decimalValue]; 
    NSInteger location; 
    for (location = 0; location < [[self.fullTransaction valueForKey:@"tDate"]count];location++) 
    { 
     CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText: [dateFormatter stringFromDate:[[self.fullTransaction valueForKey:@"tDate"] objectAtIndex:location]] textStyle:labelXTextStyle]; 
     NSLog(@"Custom Labels = %@",newLabel); 
     NSLog(@"Real Date = %@",[[self.fullTransaction valueForKey:@"tDate"] objectAtIndex:location]); 
     NSLog(@"After assigned date = %@",[dateFormatter stringFromDate:[[self.fullTransaction valueForKey:@"tDate"] objectAtIndex:location]]); 
     newLabel.tickLocation = CPTDecimalFromInt([[customTickLocations objectAtIndex:location] integerValue]); 
     newLabel.offset = 2; 
     newLabel.rotation = (1*M_PI)/4; 
     [customLabels addObject:newLabel]; 
     [xLocations addObject:[NSNumber numberWithInteger:[[customTickLocations objectAtIndex:location] integerValue]]]; 

    } 
    x.axisLabels = [NSSet setWithArray:customLabels]; 
    NSLog(@"Custom Labels = %@",customLabels); 
    x.majorTickLocations = xLocations; 
    //x.majorTickLocations = customTickLocations; 
    x.majorTickLength = 5.0f; 
    NSLog(@"Major TickLocations: %@",customTickLocations); 

    CPTXYAxis *y = axisSet.yAxis; 
    //y.orthogonalCoordinateDecimal = CPTDecimalFromCGFloat(0.0); 
    y.majorIntervalLength   = CPTDecimalFromString(@"1.0"); 
    y.minorTicksPerInterval  = 5; 
    y.majorTickLength = 5.0f; 
    y.preferredNumberOfMajorTicks = 5; 
    y.labelTextStyle = labelXTextStyle; 
} 

다음에게 nslog의 결과입니다입니다 - (NSNumber *) numberForPlot : (CPTPlot *) 플롯 필드 : (NSUInteger) fieldEnum recordIndex : (NSUInteger) idx "데이터, idx, fieldEnum.

2014-02-25 16:09:01.862 Fuel Eco[12079:70b] Number of Records for Plot = 3 
2014-02-25 16:09:01.862 Fuel Eco[12079:70b] Number of Records for Plot = 3 
2014-02-25 16:09:01.863 Fuel Eco[12079:70b] Number tobe Plot with index = 31-Jan-2014 0, 0 
2014-02-25 16:09:01.863 Fuel Eco[12079:70b] Number tobe Plot with index = 02-Feb-2014 1, 0 
2014-02-25 16:09:01.863 Fuel Eco[12079:70b] Number tobe Plot with index = 24-Feb-2014 2, 0 
2014-02-25 16:09:01.864 Fuel Eco[12079:70b] Number of Records for Plot = 3 
2014-02-25 16:09:01.864 Fuel Eco[12079:70b] Number tobe Plot with index = 10 0, 1 
2014-02-25 16:09:01.864 Fuel Eco[12079:70b] Number tobe Plot with index = 10.07 1, 1 
2014-02-25 16:09:01.865 Fuel Eco[12079:70b] Number tobe Plot with index = 8.75 2, 1 
2014-02-25 16:09:01.865 Fuel Eco[12079:70b] Number of Records for Plot = 3 

덕분에 모든

UPDATE *** 내가 이렇게 될 수있는 코드를 재 작성하고, 그것을 작동 :

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{ 
    switch (fieldEnum) 
    { 
     case CPTScatterPlotFieldX: 
     { 
      NSDecimalNumber *num = [[plotData objectAtIndex:index] objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
      return num; 
     } 
     case CPTScatterPlotFieldY: 
     { 
      if ([plot.identifier isEqual:@"Honda Plot"]) 
      { 
       NSDecimalNumber *num = [[plotData1 objectAtIndex:index] objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
       return num; 
      } 
      else 
      { 
       NSDecimalNumber *num = [[plotData objectAtIndex:index] objectForKey:[NSNumber numberWithInt:fieldEnum]]; 
       return num; 
      } 
     } 
    } 
    return nil; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self fetchResult]; 
    [self filterarray]; 
    [self filterArray1]; 

    //CGRect frame1 = CGRectMake(0,200,300,600); 
    [self generateData]; 
    //FESubView = [[CPTGraphHostingView alloc]initWithFrame:frame1]; 
    [self renderInLayer:FESubView withTheme:Nil animated:NO]; 
    } 

-(void)generateData 
{ 

    if (!plotData) { 
     //const NSTimeInterval oneDay = 24 * 60 * 60 ; 
     gregorian = [self setCalendar]; 
     NSDateComponents *dateComponents = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[[self.fullTransaction valueForKey:@"tDate" ] objectAtIndex:0]]; 
NSDate *refDate = [gregorian dateFromComponents:dateComponents]; 

     NSDate *dataDate = [[NSDate alloc]init]; 

     NSDateComponents *comps; 

     int days; 

     // Add some data 
     NSMutableArray *newData = [NSMutableArray array]; 
     NSMutableArray *newData1 = [NSMutableArray array]; 
     NSUInteger i; 



     for (i = 0; i < [[self.fullTransaction valueForKey:@"tDate"]count]; i++) { 

      dataDate = [[self.fullTransaction valueForKey:@"tDate"]objectAtIndex:i]; 
      NSLog(@"RefDate is: %@",refDate); 
      NSLog(@"DateDate is: %@",dataDate); 
      comps = [gregorian components:NSDayCalendarUnit fromDate:refDate toDate:dataDate options:0]; 
      days = [comps day]; 
      NSTimeInterval x = oneDay *days; 
      //id y    = [[self.fullTransaction valueForKey:@"tFuelEconomy"]objectAtIndex:i]; 
      int counts = [self.filteredTransaction count]; 
      id y; 
      id z; 
      int count1 = [self.filteredTransaction1 count]; 
      if (i < counts) 
      { 
      y    = [[self.filteredTransaction valueForKey:@"tFuelEconomy"]objectAtIndex:i]; 
      }else y = NULL; 
      if (i < count1) 
      { 
       z   = [[self.filteredTransaction1 valueForKey:@"tFuelEconomy"]objectAtIndex:i]; 
      }else z = NULL; 


      [newData addObject: 
      [NSDictionary dictionaryWithObjectsAndKeys: 
       [NSDecimalNumber numberWithFloat:x], [NSNumber numberWithInt:CPTScatterPlotFieldX], 
       y, [NSNumber numberWithInt:CPTScatterPlotFieldY], 
       nil]]; 
      [newData1 addObject: 
      [NSDictionary dictionaryWithObjectsAndKeys: 
       [NSDecimalNumber numberWithFloat:x], [NSNumber numberWithInt:CPTScatterPlotFieldX], 
       z, [NSNumber numberWithInt:CPTScatterPlotFieldY], 
       nil]]; 
     } 
     plotData = newData; 
     plotData1 = newData1; 
     NSLog(@"Data are: %@",plotData); 
     NSLog(@"Data are: %@",plotData1); 
    } 
} 

-(void)renderInLayer:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme animated:(BOOL)animated 
{ 
    // If you make sure your dates are calculated at noon, you shouldn't have to 
    // worry about daylight savings. If you use midnight, you will have to adjust 
    // for daylight savings time. 
    CGRect frame1 = CGRectMake(10,150,320,250); 
    FESubView = [[CPTGraphHostingView alloc]initWithFrame:frame1]; 
    FESubView.allowPinchScaling = YES; 
    [self.view addSubview:FESubView]; 

    //NSDateComponents *dateComponents = [[NSDateComponents alloc] init]; 

    gregorian = [self setCalendar]; 
    NSDateComponents *dateComponents = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:[[self.fullTransaction valueForKey:@"tDate" ] objectAtIndex:0]]; 

    NSDate *refDate = [gregorian dateFromComponents:dateComponents]; 

    NSLog(@"RefDate is :%@",refDate); 

#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE 
    CGRect bounds = layerHostingView.bounds; 
#else 
    CGRect bounds = NSRectToCGRect(layerHostingView.bounds); 
#endif 

    CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:bounds]; 
    [graph applyTheme:[CPTTheme themeNamed:kCPTDarkGradientTheme]]; 
    FESubView.hostedGraph = graph; 
    graph.title = @"Fuel Economy Graph"; 
    CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle]; 
    titleStyle.color = [CPTColor whiteColor]; 
    titleStyle.fontName = @"Helvetica-Bold"; 
    titleStyle.fontSize = 14.0f; 
    graph.titleTextStyle = titleStyle; 
    graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop; 
    graph.titleDisplacement = CGPointMake(0.0f, 10.0f); 
    // 4 - Set padding for plot area 
    [graph.plotAreaFrame setPaddingLeft:40.0f]; 
    [graph.plotAreaFrame setPaddingBottom:65.0f]; 
    [graph.plotAreaFrame setPaddingTop:3.0f]; 
    [graph.plotAreaFrame setPaddingRight:3.0f]; 

    graph.legend = [CPTLegend legendWithGraph:graph]; 
    graph.legend.fill = [CPTFill fillWithColor:[CPTColor darkGrayColor]]; 
    graph.legend.cornerRadius = 5.0; 
    graph.legend.swatchSize = CGSizeMake(25.0, 25.0); 
    graph.legendAnchor = CPTRectAnchorCenter; 

    graph.legendDisplacement = CGPointMake(2.40, 12.0); 

    // Setup scatter plot space 
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
    NSTimeInterval xLow  = 0.0f; 
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xLow) length:CPTDecimalFromFloat(oneDay * 10)]; 
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(5.0) length:CPTDecimalFromFloat(10.0f)]; 

    //symbol 

    CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy]; 
    [xRange expandRangeByFactor:CPTDecimalFromCGFloat(1)]; 
// 
    plotSpace.allowsUserInteraction = YES; 

    // Create a plot that uses the data source method 
    CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init]; 
    dataSourceLinePlot.identifier = @"Nisan Plot"; 
    CPTColor *feColor = [CPTColor redColor]; 
    CPTMutableLineStyle *feLineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy]; 
    feLineStyle.lineWidth = 2.5; 
    feLineStyle.lineColor = feColor; 
    dataSourceLinePlot.dataLineStyle = feLineStyle; 
    CPTMutableLineStyle *feSymbolLineStyle = [CPTMutableLineStyle lineStyle]; 
    feSymbolLineStyle.lineColor = feColor; 
    CPTPlotSymbol *feSymbol = [CPTPlotSymbol ellipsePlotSymbol]; 
    feSymbol.fill = [CPTFill fillWithColor:feColor]; 
    feSymbol.lineStyle = feSymbolLineStyle; 
    feSymbol.size = CGSizeMake(6.0f, 6.0f); 
    dataSourceLinePlot.plotSymbol = feSymbol; 
    CPTMutableTextStyle *feLabelStyle = [CPTMutableTextStyle textStyle]; 
    feLabelStyle.fontSize = 10; 
    feLabelStyle.color = [CPTColor whiteColor]; 
    dataSourceLinePlot.labelTextStyle = feLabelStyle; 
    dataSourceLinePlot.title = @"Nissan Terano"; 

    dataSourceLinePlot.dataSource = self; 
    [graph addPlot:dataSourceLinePlot]; 

    CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init]; 
    axisTextStyle.color = [CPTColor whiteColor]; 
    axisTextStyle.fontName = @"Helvetica-Bold"; 
    axisTextStyle.fontSize = 8.0f; 
    CPTScatterPlot *dataSourceLinePlot1 = [[CPTScatterPlot alloc] init]; 
    dataSourceLinePlot1.identifier = @"Honda Plot"; 
    CPTColor *feColor1 = [CPTColor blueColor]; 
    CPTMutableLineStyle *feLineStyle1 = [dataSourceLinePlot1.dataLineStyle mutableCopy]; 
    feLineStyle1.lineWidth = 2.5; 
    feLineStyle1.lineColor = feColor1; 
    dataSourceLinePlot1.dataLineStyle = feLineStyle1; 
    CPTMutableLineStyle *feSymbolLineStyle1 = [CPTMutableLineStyle lineStyle]; 
    feSymbolLineStyle1.lineColor = feColor1; 
    CPTPlotSymbol *feSymbol1 = [CPTPlotSymbol ellipsePlotSymbol]; 
    feSymbol1.fill = [CPTFill fillWithColor:feColor1]; 
    feSymbol1.lineStyle = feSymbolLineStyle1; 
    feSymbol1.size = CGSizeMake(6.0f, 6.0f); 
    dataSourceLinePlot1.plotSymbol = feSymbol1; 
    //CPTTextStyle *test = [CPTTextStyle textStyle]; 
    //test.fontSize = 12; 
    CPTMutableTextStyle *feLabelStyle1 = [CPTMutableTextStyle textStyle]; 
    feLabelStyle1.fontSize = 10; 
    feLabelStyle1.color = [CPTColor whiteColor]; 
    dataSourceLinePlot1.labelTextStyle = feLabelStyle1; 

    dataSourceLinePlot1.dataSource = self; 
    [graph addPlot:dataSourceLinePlot1]; 
dataSourceLinePlot1.title = @"Honda Jazz"; 
//  
    // Axes 
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 
    CPTXYAxis *x   = axisSet.xAxis; 
    x.majorIntervalLength   = CPTDecimalFromFloat(oneDay); 
    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"5"); 
    x.minorTicksPerInterval  = 0; 
    x.labelTextStyle = axisTextStyle; 
    //x.axisLineStyle = axisLineStyle; 
    //x.axisLineStyle = feLabelStyle; 
    dateFormatter = [self setDateFormatterLabel]; 
    //dateFormatter.dateStyle = kCFDateFormatterShortStyle; 

    CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter]; 
    timeFormatter.referenceDate = refDate; 
    x.labelFormatter   = timeFormatter; 
    x.labelRotation   = M_PI/4; 
    x.tickLabelDirection = CPTSignPositive; 
    x.tickDirection = CPTSignPositive; 
    //x.labelTextStyle = feLabelStyle; 
    //x.visibleRange=plotSpace.xRange; 
    x.labelOffset = -70; 

    CPTXYAxis *y = axisSet.yAxis; 
    y.majorIntervalLength   = CPTDecimalFromString(@"5.0"); 
    y.minorTicksPerInterval  = 10; 
    y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"-1"); 

    } 
+0

당신은 어떤 컴파일러 경고를 받고, 내가 [ "plotSpace의 scaleToFitPlots 라인에 대한 관심을 가지고 : [NSArray를의 arrayWithObjects : fePlot, 무기 호] ]; " "Nil"은 "nil"이어야합니다. 아니면 자동으로 올바른 StackOverflow일까요? – trumpetlicks

+0

@trumpetlicks, 응답 해 주셔서 감사합니다. 디버그 영역에는 아무 것도 없습니다. – user3350537

답변

0
  1. 난 당신이 무슨 뜻인지 모르겠어요. 질문을 더 명확하게 설명 할 수 있습니까?

  2. xLocations 세트에는 어떤 위치도 추가하지 마십시오.

    x.majorTickLocations = [NSSet setWithArray:customTickLocations]; 
    
  3. 가 왜 -expandRangeByFactor:를 사용하는 다음 customTickLocations 배열은 당신이 필요로하는 모든 위치, 단지 직접 눈금 위치 설정이 포함 된 경우?당신은 당신이 원하는 플롯 범위를 알고, 그냥 직접 설정 :

    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) 
                  length:CPTDecimalFromDouble(10.0)]; 
    
+0

안녕하세요 @ 에릭, 응답 해 주셔서 감사합니다. 1. 데이터를 살펴 보겠습니다. x 축 (2014 년 2 월 2 일)에 데이터가 표시되면 y 축은 10.07을 가리켜 야하지만 그래프에서는 그렇게 표시되지 않습니다. 내 두 번째 질문에, 나는 당신이 2 번에서 말한 것처럼 x.majorticklocations 명령을 추가하지 않았다. 3 번째 질문은 여전히 ​​y 축에 3.0,2.0,1.0을 보여준다. 나는 그래프로 y 축과 x 축에만 4.0을 보여주고 싶다. 2. 네 말이 맞아, 그 중 하나가 없어졌다. – user3350537

+0

데이터 소스는 각 값에 대한 숫자를 반환해야한다. 어떻게 날짜 문자열을 숫자로 변환하고 있습니까? –

+0

안녕하세요 @Eric. 데이터를 변경했습니다. 기본적으로 1970 년부터 nsdate 시간 간격을 사용하여 nsdate를 nsnumber로 만듭니다. – user3350537