2011-08-24 79 views
1

我只是瀏覽了一個小時的課程,找不到它!我開始搜索AAPLot項目的例子。在哪裏設置背景顏色?

我改變了一下圖表,並期待在CPTTradingRangePlot類中找到所有設置,但它不在那裏。

有很多屬性,我可以改變,但我找不到任何類的背景設置。

有人可以給我一個提示嗎?

// 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]; 

回答

0

我終於自己找到了。圖表的背景由一個主題管理。 core-plot庫的文件夾主題中有幾個主題文件,其中一個是CPTStocksTheme。 CPTStocksTheme創建了一個可以在那裏更改的藍色漸變背景。

+0

最好也是最簡單的方法就是像Chris Hodges那樣做,儘管這樣做確實有效。 – Reimius

2

背景的核心情節設置使用CPTFill對象類似於您的代碼示例中increaseFilldecreaseFill。根據您想要實現的外觀,您需要設置填充,graph.plotAreaFrame和/或graph.plotAreaFrame.plotArea。 Mac版CPTTestApp中的軸演示使用了所有三個區域的填充,以便您可以看到不同的部分。

1

您可以使用CPTColor將其設置爲xAxis或yAxis。

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

14

這是一個非常簡單的例子。這個:

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

會把你的圖形背景變成紅色。但正如埃裏克Skroch說,你可能要做到這一點...

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

和/或本...

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

取決於你想要達到的效果。