我正在使用Core-Plot作爲iPhone應用程序中的趨勢圖並且未找到如何自定義背景。我可以使用內置主題(如kCPPlainWhiteTheme)創建主題,但是如何更改它們?或創建一個新的?核心情節定製主題?
我基本上需要做的是使背景透明。
編輯/ UPDATE
我絕對測試此代碼,但它似乎並沒有工作:
//CPTheme *theme = [CPTheme themeNamed:kCPPlainWhiteTheme];
CPTheme *theme = [[CPTheme alloc]init];
chartTrend5 = (CPXYGraph *)[theme newGraph];
chartView.hostedGraph = chartTrend5;
chartTrend5.paddingLeft = 0.0;
chartTrend5.paddingTop = 0.0;
chartTrend5.paddingRight = 0.0;
chartTrend5.paddingBottom = 0.0;
chartTrend5.fill = nil;
chartTrend5.borderLineStyle = nil;
chartView.hostedGraph.fill = nil;
chartTrend5PlotSpace = (CPXYPlotSpace *)chartTrend5.defaultPlotSpace;
chartTrend5PlotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
length:CPDecimalFromFloat(5)];
// range is 0-125, but since the frame heights is 90,
// we need to convert the points to this adjusted scale. The factor is 0.72 => (90/125)
chartTrend5PlotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(0)
length:CPDecimalFromFloat(90)];
CPXYAxisSet *axisSet = (CPXYAxisSet *)chartTrend5.axisSet;
CPXYAxis *x = axisSet.xAxis;
x.majorIntervalLength = CPDecimalFromFloat(100);
//x.constantCoordinateValue = CPDecimalFromFloat(2);
x.minorTicksPerInterval = 2;
x.borderWidth = 0;
x.labelExclusionRanges = [NSArray arrayWithObjects:
[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-1)
length:CPDecimalFromFloat(800)],
nil];;
CPXYAxis *y = axisSet.yAxis;
y.majorIntervalLength = CPDecimalFromFloat(100);
y.minorTicksPerInterval = 1;
//y.constantCoordinateValue = length:CPDecimalFromFloat(2);
y.labelExclusionRanges = [NSArray arrayWithObjects:
[CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-26)
length:CPDecimalFromFloat(100)],
nil];
CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease];
dataSourceLinePlot.identifier = @"TrendChart";
dataSourceLinePlot.dataLineStyle.lineWidth = 2.f;
dataSourceLinePlot.dataLineStyle.lineColor = [CPColor colorWithComponentRed:(16/255.f)
green:(101/255.f)
blue:(122/255.f)
alpha:1];
dataSourceLinePlot.dataSource = self;
[chartTrend5 addPlot:dataSourceLinePlot];
chartTrend5.fill = nil;
// Put an area gradient under the plot above
CPColor *areaColor = [CPColor colorWithComponentRed:(212/255.f)
green:(233/255.f)
blue:(216/255.f)
alpha:1];
CPGradient *areaGradient = [CPGradient gradientWithBeginningColor:areaColor
endingColor:areaColor];
areaGradient.angle = -90.0f;
CPFill *areaGradientFill = [CPFill fillWithGradient:areaGradient];
dataSourceLinePlot.areaFill = areaGradientFill;
dataSourceLinePlot.areaBaseValue = CPDecimalFromString(@"5.25");
這裏我設置的CPXYGraph *的填充性能chartTrend5和* CPXYPlotSpace * chartTrend5PlotSpace爲零。
完美的作品。韓國社交協會。 – oscarm 2011-02-27 18:30:47
如果您擔心任何原因(滾動,調整大小等)的繪圖性能,將這些填充屬性設置爲零將告訴核心繪圖沒有任何繪製。這樣它就知道跳過設置剪裁區域並繪製不會出現在屏幕上的像素。 – 2011-02-27 19:23:02
@Eric - 感謝您指出。我替換了一些清晰填充的代碼,只需將該填充設置爲零,並在不斷重繪陰謀時節省了我的Mac上大約2-3%的CPU負載。 – 2011-02-28 15:32:46