core plot custom Theme?

前端 未结 4 404
失恋的感觉
失恋的感觉 2021-02-04 12:40

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 kCPPlainWhiteThe

相关标签:
4条回答
  • 2021-02-04 13:01

    Themes are just a convenient way to set a lot of the style properties at once. You can set any of them individually to customize the look. Any time you want an area to be transparent, you can set its fill to nil. Same with line styles--set them to nil to prevent a line from being drawn.

    There are two "background" areas that you might be concerned with. The graph has a fill as does the plot area. The plot area is the region where the plots are drawn. Set the fill property on both of these to nil to make the background transparent.

    0 讨论(0)
  • 2021-02-04 13:08

    I used the .fill and .plot.AreaFrame.fill properties :

    plot = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
    CPTTheme *theme = [CPTTheme themeNamed:kCPTSlateTheme];
    [plot applyTheme:theme];
    self.graph.collapsesLayers = NO;
    self.graph.hostedGraph = plot;
    
    plot.paddingLeft = 1.0;
    plot.paddingTop = 1.0;
    plot.paddingRight = 1.0;
    plot.paddingBottom = 1.0;
    plot.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
    plot.plotAreaFrame.fill = [CPTFill fillWithColor:[CPTColor clearColor]];
    

    This works for me.

    0 讨论(0)
  • 2021-02-04 13:13

    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]];
    
    0 讨论(0)
  • 2021-02-04 13:18

    I tried this & it works for me:

    // Here 'hostingView' is your CPTGraphHostingView to
    // which you add your graph
    UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
    [hostingView addSubview:backgorundImage];
    [hostingView sendSubviewToBack:backgroundImage];
    
    0 讨论(0)
提交回复
热议问题