核心情节定制主题? [英] core plot custom Theme?

查看:156
本文介绍了核心情节定制主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone应用程序中使用Core-Plot作为趋势图,但还没有找到如何自定义背景。我可以使用内置主题创建主题,如kCPPlainWhiteTheme,但我该如何更改它们?或者创建一个新的?

I'm using Core-Plot for a trend chart in an iPhone app and haven't found how to customize the background. I can create a theme using the built-in themes, like kCPPlainWhiteTheme, but how can I change them? or create a new one?

我基本上需要做的是让背景透明化。

What i basically need to do is make the background transparent.

编辑/更新

我测试了这段代码,但它没有似乎工作:

I jus tested this code but it doesn't seem to work:

    //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 为零。

推荐答案

除了Eric建议的,您还可以尝试设置填充到清晰的颜色。例如,我过去曾使用过这个来为图表提供透明背景:

In addition to what Eric suggests, you can also try setting the fill to a clear color. For example, I've used this in the past to provide a transparent background to graphs:

CPTTheme *theme = [CPTTheme themeNamed:kCPPlainWhiteTheme];
graph = (CPTXYGraph *)[theme newGraph];

graph.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
graph.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]];

这篇关于核心情节定制主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆