2011-08-24 76 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]; 

取决于你想要达到的效果。