【问题标题】:Coreplot iOS - Remove border line around pie chartCoreplot iOS - 删除饼图周围的边框线
【发布时间】:2013-07-17 10:26:25
【问题描述】:

我有一个通过 Coreplot 生成的饼图。它在图表周围和所有部分都画了一条黑线,如下所示:

我使用以下代码生成图表:

-(CPTFill *)sliceFillForPieChart:(CPTPieChart *)pieChart recordIndex:(NSUInteger)index
{
CPTFill *areaGradientFill ;

if (index==0)
return areaGradientFill= [CPTFill fillWithColor:[CPTColor colorWithComponentRed:0.0f/255.0f green:111.0f/255.0f blue:115.0f/255.0f alpha:1.0f]];
else if (index==1)
    return areaGradientFill= [CPTFill fillWithColor:[CPTColor colorWithComponentRed:171.0f/255.0f green:213.0f/255.0f blue:199.0f/255.0f alpha:1.0f]];
else if (index==2)
    return areaGradientFill= [CPTFill fillWithColor:[CPTColor yellowColor]];

return areaGradientFill;
}

-(void)constructPieChart:(NSString *)datain;
{

NSArray *strings = [datain componentsSeparatedByString:@","];

dataforcharts = [datain componentsSeparatedByString:@","];

NSLog(@"dataforcharts: %@", dataforcharts);

// Create pieChart from theme
pieGraph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTTheme *theme = [CPTTheme themeNamed:kCPTPlainWhiteTheme];
[pieGraph applyTheme:theme];
pieChartView.hostedGraph             = pieGraph;
pieGraph.plotAreaFrame.borderLineStyle = nil;
pieGraph.plotAreaFrame.masksToBorder = NO;

pieGraph.paddingLeft   = 20.0;
pieGraph.paddingTop    = 20.0;
pieGraph.paddingRight  = 20.0;
pieGraph.paddingBottom = 20.0;

pieGraph.axisSet = nil;

// Prepare a radial overlay gradient for shading/gloss
CPTGradient *overlayGradient = [[CPTGradient alloc] init];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient              = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.0];
overlayGradient              = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.3] atPosition:0.9];
overlayGradient              = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.7] atPosition:1.0];

// Add pie chart
piePlot                 = [[CPTPieChart alloc] init];
piePlot.dataSource      = self;
piePlot.pieRadius       = 100.0;
piePlot.pieInnerRadius  = 50.0;
piePlot.identifier      = @"Pie Chart 1";
piePlot.startAngle      = M_PI_4;

  //  piePlot.sliceDirection  = CPTPieDirectionCounterClockwise;
piePlot.borderLineStyle = [CPTLineStyle lineStyle];
piePlot.labelOffset     = -40.0;
piePlot.overlayFill     = [CPTFill fillWithGradient:overlayGradient];
[pieGraph addPlot:piePlot];

CPTMutableTextStyle *textStyle = [CPTMutableTextStyle textStyle];
textStyle.color = [CPTColor blackColor];
textStyle.fontName = @"Helvetica-Bold";
textStyle.fontSize = 16.0f;

pieGraph.title=@"Chart1";

pieGraph.titleTextStyle = textStyle;
pieGraph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
pieGraph.titleDisplacement = CGPointMake(0.0f, -1.0f);

int i = [[strings objectAtIndex:0] intValue];
int f = [[strings objectAtIndex:1] intValue];

NSLog(@"Int1: %i", i);
NSLog(@"Int2: %i", f);

// Add some initial data
NSMutableArray *contentArray = [NSMutableArray arrayWithObjects:[NSNumber numberWithDouble:i], [NSNumber numberWithDouble:f], nil];
self.dataForChart = contentArray;

CPTLegend *theLegend = [CPTLegend legendWithGraph:pieGraph];
theLegend.numberOfColumns = 2;
theLegend.fill = [CPTFill fillWithColor:[CPTColor whiteColor]];
theLegend.borderLineStyle = [CPTLineStyle lineStyle];
theLegend.cornerRadius = 5.0;

pieGraph.legend = theLegend;

pieGraph.legendAnchor = CPTRectAnchorBottom;
pieGraph.legendDisplacement = CGPointMake(0.0, -0.0);
}

我想删除图表周围的黑线。我已经尝试将borderLineStyle 设置为nil 但这似乎没有任何效果。

感谢任何帮助。

谢谢!

亚当

【问题讨论】:

    标签: ios objective-c core-plot


    【解决方案1】:

    使用它并再次调试,它正在工作。

    piePlot.borderLineStyle = nil;
    

    【讨论】:

    • 确实有效,只是我放错地方了。由于某种原因,它需要低于我设置 overlayFill 的位置。嗯,现在一切正常。谢谢!
    • 是否可以用一些颜色填充内圈(如上图所示) ??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 2018-03-12
    • 1970-01-01
    相关资源
    最近更新 更多