2009-11-17 5 views
2

Je suis allé à travers le tutoriel ici: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application, et je peux obtenir un graphique pour montrer, mais je ne vois pas de graduations ou d'étiquettes sur mon ensemble d'axes. Y a-t-il quelque chose de simple que je néglige? Ci-dessous est mon code pour créer le graphique, et j'ai également mis en œuvre les fonctions de délégué. Je vois l'axe et l'intrigue, mais pas les marques ou les étiquettes de l'axe.iPhone Core-Plot Tick marques ne montrant pas

Merci pour toute aide que vous pouvez donner.

- (void) showGraph { 

    graph = [[CPXYGraph alloc] initWithFrame: CGRectMake(0,0, 320, 320)]; 

    CPLayerHostingView *graphView = [[CPLayerHostingView alloc] initWithFrame:CGRectMake(0,0, 320, 320)]; 
    graphView.backgroundColor = [UIColor blueColor]; 

    AppDelegate *t = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [t.mapVC.view addSubview:graphView]; 

    graphView.hostedLayer = graph; 
    graph.paddingLeft = 20.0; 
    graph.paddingTop = 20.0; 
    graph.paddingRight = 20.0; 
    graph.paddingBottom = 20.0; 

    float minElevation = 0; 
    float maxElevation = 10; 
    float minTime = 0; 
    float maxTime = 5; 

    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minTime) 
               length:CPDecimalFromFloat(maxTime)]; 
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minElevation) 
               length:CPDecimalFromFloat(maxElevation)]; 

    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; 

    CPLineStyle *blackStyle = [CPLineStyle lineStyle]; 
    blackStyle.lineColor = [CPColor blackColor]; 
    blackStyle.lineWidth = 5.0f; 
    CPLineStyle *whiteStyle = [CPLineStyle lineStyle]; 
    whiteStyle.lineColor = [CPColor whiteColor]; 
    whiteStyle.lineWidth = 5.0f; 

    axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"]decimalValue]; 

    axisSet.xAxis.minorTicksPerInterval = 4; 
    axisSet.xAxis.majorTickLineStyle = whiteStyle; 
    axisSet.xAxis.minorTickLineStyle = whiteStyle; 
    axisSet.xAxis.axisLineStyle = blackStyle; 
    axisSet.xAxis.minorTickLength = 5.0f; 
    axisSet.xAxis.majorTickLength = 10.0f; 
    axisSet.xAxis.labelOffset = 3.0f; 

    axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"]decimalValue]; 
    axisSet.yAxis.minorTicksPerInterval = 4; 
    axisSet.yAxis.majorTickLineStyle = blackStyle; 
    axisSet.yAxis.minorTickLineStyle = blackStyle; 
    axisSet.yAxis.axisLineStyle = whiteStyle; 
    axisSet.yAxis.minorTickLength = 5.0f; 
    axisSet.yAxis.majorTickLength = 10.0f; 
    axisSet.yAxis.labelOffset = 3.0f; 

    CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] 
            initWithFrame:graph.bounds] autorelease]; 
    xSquaredPlot.identifier = @"X Squared Plot"; 
    xSquaredPlot.dataLineStyle.lineWidth = 2.0f; 
    xSquaredPlot.dataLineStyle.lineColor = [CPColor greenColor]; 
    xSquaredPlot.dataSource = self; 
    [graph addPlot:xSquaredPlot]; 

    CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol]; 
    greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]]; 
    greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0); 

    xSquaredPlot.plotSymbol = greenCirclePlotSymbol; 
} 

Répondre

6

Vous avez besoin un peu d'espace autour de l'extérieur des axes. Core Plot ne le fait pas encore automatiquement pour vous. Essayez d'ajouter un peu de remplissage à graph.plotArea.plotGroup et graph.plotArea.axisSet. Voir le graphique du bar dans l'application de test iPhone pour un exemple.

+0

Oui, malheureusement, l'API de la bibliothèque a légèrement changé depuis la publication de ce tutoriel. Nous essayons de maintenir les exemples d'applications pour montrer la manière correcte d'interagir avec la bibliothèque. –