2011-08-24 5 views
1

Je venais de parcourir les cours pendant une heure et je ne peux pas le trouver! J'ai commencé par chercher l'exemple du projet AAPLot.où définir la couleur de fond?

J'ai légèrement modifié le graphique et je m'attendais à trouver tous les paramètres dans la classe CPTTradingRangePlot mais ce n'est pas le cas.

Il y a beaucoup de propriétés que je peux changer, mais je ne peux pas trouver les paramètres d'arrière-plan dans l'une des classes.

Quelqu'un pourrait-il me donner un indice?

// OHLC plot 
CPTMutableLineStyle *whiteLineStyle = [CPTMutableLineStyle lineStyle]; 
whiteLineStyle.lineColor = [CPTColor whiteColor]; 
whiteLineStyle.lineWidth = 1.0f; 
CPTTradingRangePlot *ohlcPlot = [[[CPTTradingRangePlot alloc] initWithFrame:graph.bounds] autorelease]; 
ohlcPlot.identifier = @"OHLC"; 
ohlcPlot.lineStyle = whiteLineStyle; 
ohlcPlot.barWidth = 4.0f; 
ohlcPlot.increaseFill = [(CPTFill *)[CPTFill alloc] initWithColor:[CPTColor greenColor]]; 
ohlcPlot.decreaseFill = [(CPTFill *)[CPTFill alloc] initWithColor:[CPTColor redColor]]; 
    CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle]; 
whiteTextStyle.color = [CPTColor whiteColor]; 
    whiteTextStyle.fontSize = 12.0; 
    ohlcPlot.labelTextStyle = whiteTextStyle; 
    ohlcPlot.labelOffset = 5.0; 
ohlcPlot.stickLength = 2.0f; 
ohlcPlot.dataSource = self; 
ohlcPlot.plotStyle = CPTTradingRangePlotStyleCandleStick; 
[graph addPlot:ohlcPlot]; 

Répondre

0

J'ai finalement trouvé par moi-même. l'arrière-plan du graphique est géré par un thème. Il y a plusieurs fichiers de thème dans le thème de dossier de la bibliothèque de noyau-intrigue et l'un d'entre eux est CPTStocksTheme. Le CPTStocksTheme crée un fond dégradé bleu qui peut être modifié ici.

+0

Le meilleur et le plus simple est de le faire comme l'exemple de Chris Hodges, même si cela fonctionne. – Reimius

2

Fonds impérieux en matière de terrain définies à l'aide CPTFill objets similaires au increaseFill et decreaseFill dans votre exemple de code. En fonction de l'apparence que vous souhaitez obtenir, vous devez définir le remplissage sur , graph.plotAreaFrame et/ou graph.plotAreaFrame.plotArea. La démonstration de l'axe dans la version Mac de CPTTestApp utilise des remplissages dans les trois zones afin que vous puissiez voir les différentes parties.

1

Vous pouvez le définir dans xAxis ou yAxis en utilisant CPTColor.

axisSet.yAxis.alternatingBandFills = [NSArray arrayWithObjects: [CPTColor redColor], [CPTColor whiteColor], [CPTColor purpleColor], nil];

14

Voici un exemple très simple. Ceci:

CPTColor *your_color = [CPTColor colorWithComponentRed:1 green:0 blue:0 alpha:1]; 
your_graph.fill = [CPTFill fillWithColor:your_color]; 

va transformer le fond de votre graphique en rouge. Mais comme Eric Skroch dit, vous pouvez le faire ...

your_graph.plotAreaFrame.fill = [CPTFill fillWithColor:your_color]; 

et/ou ... ce

your_graph.plotAreaFrame.plotArea.fill = [CPTFill fillWithColor:your_color]; 

en fonction du résultat que vous souhaitez atteindre.