Soucis avec Core Plot

CiretenCireten Membre
août 2012 modifié dans API UIKit #1
Bonjour,



Je travaille sur mon premier projet pour Iphone, je vais essayer de décrire mon problème.



J'utilise Core plot, ça fonctionne plutôt bien. Mais je suis devant un problème. Dans un controlleur de vue, j'ai mis en place un scrollview dans lequel je mets des vues contenant des graphiques.



Cela marche, j'ai bien mes graphiques, mais le datasource du core plot n'est pas exécuté au bon moment, ce qui fait que mes courbes ne s'affichent pas.



Voici mon code dans le viewdidload :




[font=Menlo][size=2]	[color=#35568a]for[/color]([color=#c35900]NSString[/color] *type [color=#35568a]in[/color] arrayType)[/size][/font]<br />
[font=Menlo][size=2]	{[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]		[/color][color=#c35900]UIView[/color][color=#000000] *viewGraph = [[[/color][color=#c35900]UIView[/color][color=#000000] [/color]alloc[color=#000000]] [/color]initWithFrame[color=#000000]:[/color]CGRectMake[color=#000000](x, [/color][color=#35568a]0[/color][color=#000000], [/color][color=#35568a]self[/color][color=#000000].[/color]view[color=#000000].[/color]frame[color=#000000].[/color]size[color=#000000].[/color]width[color=#000000], [/color]scrollView[color=#000000].[/color]frame[color=#000000].[/color]size[color=#000000].[/color]height[color=#000000])];[/color][/size][/font][/color]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]		[[/color]scrollView[color=#000000] [/color]addSubview[color=#000000]:[[/color][color=#35568a]self[/color][color=#000000] [/color]makeGraphe[color=#000000]:type [/color]inView[color=#000000]:viewGraph [/color]withArray[color=#000000]:array]];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]		[viewGraph [color=#587ea8]release[/color]];[/size][/font]<br />
[font=Menlo][size=2]		x += [color=#35568a]self[/color].[color=#587ea8]view[/color].[color=#587ea8]frame[/color].[color=#587ea8]size[/color].[color=#587ea8]width[/color];[/size][/font]<br />
[font=Menlo][size=2]	}[/size][/font]




et voici mon makegraphe :




[font=Menlo][size=2]-([color=#c35900]UIView[/color] *)makeGraphe:([color=#c35900]NSString[/color] *)type inView:([color=#c35900]UIView[/color] *)viewGraph withArray:([color=#c35900]NSArray[/color] *)array[/size][/font]<br />
[font=Menlo][size=2]{[/size][/font]<br />
[font=Menlo][size=2]	[color=#587ea8]NSLog[/color]([color=#e82300]@&quot;%@&quot;[/color], type);[/size][/font]<br />
[font=Menlo][size=2]	[color=#c35900]GrapheValue[/color] *graphValues = [[[color=#c35900]GrapheValue[/color] [color=#587ea8]alloc[/color]] [color=#587ea8]init[/color]];[/size][/font]<br />
[font=Menlo][size=2]	[color=#c35900]NSArray[/color] *graphArray = [[[color=#c35900]NSArray[/color] [color=#587ea8]alloc[/color]] [color=#587ea8]init[/color]];[/size][/font]<br />
<br />
[font=Menlo][size=2]	[color=#35568a]if[/color]([type [color=#587ea8]isEqualToString[/color]:[color=#e82300]@&quot;OneYear&quot;[/color]]) {[/size][/font]<br />
[font=Menlo][size=2]		graphArray = [graphValues [color=#587ea8]grapheOneYear[/color]:array];[/size][/font]<br />
[font=Menlo][size=2]	}[color=#35568a]else[/color] [color=#35568a]if[/color] ([type [color=#587ea8]isEqualToString[/color]:[color=#e82300]@&quot;SixMonth&quot;[/color]]) {[/size][/font]<br />
[font=Menlo][size=2]		graphArray = [graphValues [color=#587ea8]grapheSixMonth[/color]:array];[/size][/font]<br />
[font=Menlo][size=2]	}[color=#35568a]else[/color] [color=#35568a]if[/color] ([type [color=#587ea8]isEqualToString[/color]:[color=#e82300]@&quot;ThreeMonth&quot;[/color]]) {[/size][/font]<br />
[font=Menlo][size=2]		graphArray = [graphValues [color=#587ea8]grapheThreeMonth[/color]:array];[/size][/font]<br />
[font=Menlo][size=2]	}[color=#35568a]else[/color] [color=#35568a]if[/color] ([type [color=#587ea8]isEqualToString[/color]:[color=#e82300]@&quot;OneMonth&quot;[/color]]) {[/size][/font]<br />
[font=Menlo][size=2]		graphArray = [graphValues [color=#587ea8]grapheOneMonth[/color]:array];[/size][/font]<br />
[font=Menlo][size=2]	}[color=#35568a]else[/color] [color=#35568a]if[/color] ([type [color=#587ea8]isEqualToString[/color]:[color=#e82300]@&quot;OneWeek&quot;[/color]]) {[/size][/font]<br />
[font=Menlo][size=2]		graphArray = [graphValues [color=#587ea8]grapheOneWeek[/color]:array];[/size][/font]<br />
[font=Menlo][size=2]	}[color=#35568a]else[/color] {[/size][/font]<br />
[font=Menlo][size=2]		graphArray = [graphValues [color=#587ea8]grapheOneDay[/color]:array];[/size][/font]<br />
[font=Menlo][size=2]	}[/size][/font]<br />
<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	[/color]dataForPlot[color=#000000] = [[[/color][color=#c35900]NSMutableArray[/color][color=#000000] [/color]alloc[color=#000000]] [/color]initWithArray[color=#000000]:graphArray];[/color][/size][/font][/color]<br />
<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	[/color]NSLog[color=#000000]([/color][color=#e82300]@&quot;%@ --- %@&quot;[/color][color=#000000], type, [/color]dataForPlot[color=#000000]);[/color][/size][/font][/color]<br />
<br />
[color=#CF8724][font=Menlo][size=2][color=#000000]	[/color]// Valeurs des axes du graphique[/size][/font][/color]<br />
[font=Menlo][size=2]	[color=#35568a]float[/color] xAxisMin = [color=#35568a]0[/color];[/size][/font]<br />
[font=Menlo][size=2]	[color=#35568a]float[/color] xAxisMax = [[color=#587ea8]dataForPlot[/color] [color=#587ea8]count[/color]];[/size][/font]<br />
[font=Menlo][size=2]	[color=#35568a]float[/color] yAxisMin = [color=#587ea8]floorf[/color]([graphValues [color=#587ea8]minValue[/color]] / [color=#35568a]100[/color]) * [color=#35568a]100[/color];[/size][/font]<br />
[font=Menlo][size=2]	[color=#35568a]float[/color] yAxisMax = [color=#587ea8]ceil[/color]([graphValues [color=#587ea8]maxValue[/color]] / [color=#35568a]100[/color]) * [color=#35568a]100[/color];[/size][/font]<br />
<br />
[color=#CF8724][font=Menlo][size=2][color=#000000]	[/color]// Création du graphique[/size][/font][/color]<br />
[font=Menlo][size=2]	[color=#c35900]CPTXYGraph[/color] *graph = [[[color=#c35900]CPTXYGraph[/color] [color=#587ea8]alloc[/color]] [color=#587ea8]initWithFrame[/color]:viewGraph.[color=#587ea8]bounds[/color]];[/size][/font]<br />
<br />
[font=Menlo][size=2]	graph.[color=#587ea8]paddingTop[/color] = [color=#35568a]5[/color];[/size][/font]<br />
[font=Menlo][size=2]	graph.[color=#587ea8]paddingBottom[/color] = [color=#35568a]10[/color];[/size][/font]<br />
[font=Menlo][size=2]	graph.[color=#587ea8]paddingLeft[/color] = [color=#35568a]10[/color];[/size][/font]<br />
[font=Menlo][size=2]	graph.[color=#587ea8]paddingRight[/color] = [color=#35568a]10[/color];[/size][/font]<br />
<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	graph.[/color]plotAreaFrame[color=#000000].[/color]paddingLeft[color=#000000] = [/color][color=#35568a]30[/color][color=#000000];[/color][/size][/font][/color]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	graph.[/color]plotAreaFrame[color=#000000].[/color]paddingBottom[color=#000000] = [/color][color=#35568a]15[/color][color=#000000];[/color][/size][/font][/color]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	graph.[/color]plotAreaFrame[color=#000000].[/color]paddingRight[color=#000000] = [/color][color=#35568a]10[/color][color=#000000];[/color][/size][/font][/color]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	graph.[/color]plotAreaFrame[color=#000000].[/color]paddingTop[color=#000000] = [/color][color=#35568a]10[/color][color=#000000];[/color][/size][/font][/color]<br />
<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	[/color][color=#c35900]CPTTheme[/color][color=#000000] *theme = [[/color][color=#c35900]CPTTheme[/color][color=#000000] [/color]themeNamed[color=#000000]:[/color]kCPTStocksTheme[color=#000000]];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	[graph [color=#587ea8]applyTheme[/color]:theme];[/size][/font]<br />
<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	[/color][color=#c35900]CPTGraphHostingView[/color][color=#000000] *graphHostingView = [[[/color][color=#c35900]CPTGraphHostingView[/color][color=#000000] [/color]alloc[color=#000000]] [/color]initWithFrame[color=#000000]:[/color]CGRectMake[color=#000000]([/color][color=#35568a]0[/color][color=#000000], [/color][color=#35568a]0[/color][color=#000000], [/color][color=#35568a]self[/color][color=#000000].[/color]view[color=#000000].[/color]frame[color=#000000].[/color]size[color=#000000].[/color]width[color=#000000], [/color]scrollView[color=#000000].[/color]frame[color=#000000].[/color]size[color=#000000].[/color]height[color=#000000] )];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	graphHostingView.[color=#587ea8]hostedGraph[/color] = graph;[/size][/font]<br />
<br />
[font=Menlo][size=2]	graphHostingView.[color=#587ea8]collapsesLayers[/color] = [color=#35568a]YES[/color];[/size][/font]<br />
[font=Menlo][size=2]	graphHostingView.[color=#587ea8]backgroundColor[/color] = [[color=#c35900]UIColor[/color] [color=#587ea8]clearColor[/color]];[/size][/font]<br />
[font=Menlo][size=2]	[viewGraph [color=#587ea8]addSubview[/color]:graphHostingView];[/size][/font]<br />
<br />
[color=#C35900][font=Menlo][size=2][color=#000000]	[/color]CPTMutableLineStyle[color=#000000] *majorGridLineStyle = [[/color]CPTMutableLineStyle[color=#000000] [/color][color=#587ea8]lineStyle[/color][color=#000000]];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	majorGridLineStyle.[color=#587ea8]lineWidth[/color] = [color=#35568a]0.75[/color];[/size][/font]<br />
[font=Menlo][size=2]	majorGridLineStyle.[color=#587ea8]lineColor[/color] = [[color=#c35900]CPTColor[/color] [color=#587ea8]whiteColor[/color]];[/size][/font]<br />
<br />
<br />
[color=#C35900][font=Menlo][size=2][color=#000000]	[/color]CPTMutableTextStyle[color=#000000] *textStyle = [[/color]CPTMutableTextStyle[color=#000000] [/color][color=#587ea8]textStyle[/color][color=#000000]];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	textStyle.[color=#587ea8]fontName[/color] = [color=#e82300]@&quot;Helvetica&quot;[/color];[/size][/font]<br />
[font=Menlo][size=2]	textStyle.[color=#587ea8]fontSize[/color] = [color=#35568a]8[/color];[/size][/font]<br />
[font=Menlo][size=2]	textStyle.[color=#587ea8]color[/color] = [[color=#c35900]CPTColor[/color] [color=#587ea8]whiteColor[/color]];[/size][/font]<br />
<br />
[font=Menlo][size=2]	[color=#c35900]CPTXYPlotSpace[/color] * plotspace = ([color=#c35900]CPTXYPlotSpace[/color] *) graph.[color=#587ea8]defaultPlotSpace[/color];[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	plotspace.[/color]allowsUserInteraction[color=#000000] = [/color][color=#35568a]NO[/color][color=#000000];[/color][/size][/font][/color]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	plotspace.[/color]xRange[color=#000000] = [[/color][color=#c35900]CPTPlotRange[/color][color=#000000] [/color]plotRangeWithLocation[color=#000000]:[/color]CPTDecimalFromFloat[color=#000000](xAxisMin) [/color]length[color=#000000]:[/color]CPTDecimalFromFloat[color=#000000](xAxisMax)];[/color][/size][/font][/color]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	plotspace.[/color]yRange[color=#000000] = [[/color][color=#c35900]CPTPlotRange[/color][color=#000000] [/color]plotRangeWithLocation[color=#000000]:[/color]CPTDecimalFromFloat[color=#000000](yAxisMin) [/color]length[color=#000000]:[/color]CPTDecimalFromInt[color=#000000](yAxisMax)];[/color][/size][/font][/color]<br />
<br />
[color=#CF8724][font=Menlo][size=2][color=#000000]	[/color]// Axe X[/size][/font][/color]<br />
[font=Menlo][size=2]	[color=#c35900]CPTXYAxisSet[/color] *axisSet = ([color=#c35900]CPTXYAxisSet[/color] *)graph.[color=#587ea8]axisSet[/color];[/size][/font]<br />
[font=Menlo][size=2]	[color=#c35900]CPTXYAxis[/color] *x = axisSet.[color=#587ea8]xAxis[/color];[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	x.[/color]majorIntervalLength[color=#000000] = [/color]CPTDecimalFromString[color=#000000]([/color][color=#e82300]@&quot;30&quot;[/color][color=#000000]);[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	x.[color=#587ea8]axisLineStyle[/color] = majorGridLineStyle;[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	x.[/color]majorTickLength[color=#000000] = [/color][color=#35568a]4[/color][color=#000000];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	x.[color=#587ea8]majorGridLineStyle[/color] = majorGridLineStyle;[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	x.[/color]minorTicksPerInterval[color=#000000] = [/color][color=#35568a]0[/color][color=#000000];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	x.[color=#587ea8]minorTickLineStyle[/color] = majorGridLineStyle;[/size][/font]<br />
[font=Menlo][size=2]	x.[color=#587ea8]labelTextStyle[/color] = textStyle;[/size][/font]<br />
<br />
[color=#CF8724][font=Menlo][size=2][color=#000000]	[/color]// Axe Y[/size][/font][/color]<br />
[font=Menlo][size=2]	[color=#c35900]CPTXYAxis[/color] *y = axisSet.[color=#587ea8]yAxis[/color];[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	y.[/color]majorIntervalLength[color=#000000] = [/color]CPTDecimalFromString[color=#000000]([/color][color=#e82300]@&quot;100&quot;[/color][color=#000000]);[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	y.[color=#587ea8]axisLineStyle[/color] = majorGridLineStyle;[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	y.[/color]majorTickLength[color=#000000] = [/color][color=#35568a]4[/color][color=#000000];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	y.[color=#587ea8]majorTickLineStyle[/color] = majorGridLineStyle;[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	y.[/color]minorTicksPerInterval[color=#000000] = [/color][color=#35568a]1[/color][color=#000000];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	y.[color=#587ea8]minorTickLineStyle[/color] = majorGridLineStyle;[/size][/font]<br />
[font=Menlo][size=2]	y.[color=#587ea8]labelTextStyle[/color] = textStyle;[/size][/font]<br />
[font=Menlo][size=2]	y.[color=#587ea8]majorGridLineStyle[/color] = majorGridLineStyle;[/size][/font]<br />
<br />
[color=#CF8724][font=Menlo][size=2][color=#000000]	[/color]// Ligne du graphique[/size][/font][/color]<br />
[font=Menlo][size=2]	[color=#c35900]CPTScatterPlot[/color] *boundLinePlot = [[[color=#c35900]CPTScatterPlot[/color] [color=#587ea8]alloc[/color]] [color=#587ea8]init[/color]];[/size][/font]<br />
[color=#C35900][font=Menlo][size=2][color=#000000]	[/color]CPTMutableLineStyle[color=#000000] *lineStyle = [[/color]CPTMutableLineStyle[color=#000000] [/color][color=#587ea8]lineStyle[/color][color=#000000]];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	lineStyle.[color=#587ea8]miterLimit[/color] = [color=#35568a]1.0f[/color];[/size][/font]<br />
[font=Menlo][size=2]	lineStyle.[color=#587ea8]lineWidth[/color] = [color=#35568a]1.0f[/color];[/size][/font]<br />
[font=Menlo][size=2]	lineStyle.[color=#587ea8]lineColor[/color] = [[color=#c35900]CPTColor[/color] [color=#587ea8]redColor[/color]];[/size][/font]<br />
[font=Menlo][size=2]	boundLinePlot.[color=#587ea8]dataLineStyle[/color] = lineStyle;[/size][/font]<br />
[font=Menlo][size=2]	boundLinePlot.[color=#587ea8]identifier[/color] = [[[color=#c35900]NSString[/color] [color=#587ea8]alloc[/color]] [color=#587ea8]initWithString[/color]:type];[/size][/font]<br />
[font=Menlo][size=2]	boundLinePlot.[color=#587ea8]dataSource[/color] = [color=#35568a]self[/color];[/size][/font]<br />
[color=#CF8724][font=Menlo][size=2]//	boundLinePlot.delegate = self;[/size][/font][/color]<br />
<br />
[font=Menlo][size=2][graph [color=#587ea8]addPlot[/color]:boundLinePlot];[/size][/font]<br />
<br />
[font=Menlo][size=2]	[boundLinePlot [color=#587ea8]release[/color]];[/size][/font]<br />
[font=Menlo][size=2]	[graphHostingView [color=#587ea8]release[/color]];[/size][/font]<br />
[font=Menlo][size=2]	[graphValues [color=#587ea8]release[/color]];[/size][/font]<br />
[font=Menlo][size=2]	[graph [color=#587ea8]release[/color]];[/size][/font]<br />
<br />
[font=Menlo][size=2]	[color=#35568a]return[/color] viewGraph;[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]




Et j'ai evidemment mes deux méthodes provenant du datasource :




[font=Menlo][size=2]-([color=#c35900]NSUInteger[/color])numberOfRecordsForPlot:([color=#c35900]CPTPlot[/color] *)plot {[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	[/color]NSLog[color=#000000]([/color][color=#e82300]@&quot;%u&quot;[/color][color=#000000], [[/color]dataForPlot[color=#000000] [/color]count[color=#000000]]);[/color][/size][/font][/color]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	[/color][color=#35568a]return[/color][color=#000000] [[/color]dataForPlot[color=#000000] [/color]count[color=#000000]];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]}[/size][/font]<br />
<br />
[font=Menlo][size=2]-([color=#c35900]NSNumber[/color] *)numberForPlot:([color=#c35900]CPTPlot[/color] *)plot field:([color=#c35900]NSUInteger[/color])fieldEnum recordIndex:([color=#c35900]NSUInteger[/color])index  {[/size][/font]<br />
[color=#587EA8][font=Menlo][size=2][color=#000000]	[/color][color=#35568a]return[/color][color=#000000] [[[/color]dataForPlot[color=#000000] [/color]objectAtIndex[color=#000000]:index] [/color]valueForKey[color=#000000]:(fieldEnum == [/color]CPTScatterPlotFieldX[color=#000000] ? [/color][color=#e82300]@&quot;x&quot;[/color][color=#000000] : [/color][color=#e82300]@&quot;y&quot;[/color][color=#000000])];[/color][/size][/font][/color]<br />
[font=Menlo][size=2]}[/size][/font]




Une précision :



J'ai mis des NSLog pour suivre l'exécution du process, et il execute tous les makegraphe et seulement ensuite les methode du datasource. Je pense que le souci vient de là , mais je ne trouve pas de solution.

Quand je ne mets qu'un seul graphique, cela fonctionne.



Merci d'avance pour votre aide.

Réponses

  • Merci de te présenter et d'utiliser la balise Code image/wink.png' class='bbc_emoticon' alt=';)' />
  • Oups, désolé.



    Je suis nouveau sur ce forum. J'ai complété ma fiche.



    Bonne journée.
Connectez-vous ou Inscrivez-vous pour répondre.