CorePlot学习 使用技巧

corePlot 使用技巧:

//设置内边距:

graph.plotAreaFrame.paddingLeft   +=5;

graph.plotAreaFrame.paddingTop    +=5;

graph.plotAreaFrame.paddingRight  +=5;

graph.plotAreaFrame.paddingBottom +=17.5;

 

[self setAllowPinchScaling:NO];//禁止缩放

 

//设置坐标只能按照X轴横向滑动:(其他方向请自行理解)

plotSpace.yRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(1)];



plotSpace.globalYRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(1)];



plotSpace.xRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(1)length:CPTDecimalFromFloat(1)];



plotSpace.globalXRange = [CPTPlotRangeplotRangeWithLocation:CPTDecimalFromInt(0)length:CPTDecimalFromFloat(2)];



 
//自定义轴label:

x.axisLabels          = [self buildLabelTitle];



x.labelingPolicy      = CPTAxisLabelingPolicyNone;//当设置这个Policy之后,坐标轴label及背景线tick都需要自己绘制,否则显示为空,请不要过度惊慌



x.minorTickLocations  = [NSSetsetWithArray:locationLabels];



 

- (NSMutableSet*)buildLabelTitle



{



    NSMutableSet *newAxisLabels = [NSMutableSetset];



   



    CPTMutableTextStyle *textStyleB = [CPTMutableTextStyletextStyle];



    textStyleB.color = [CPTColorcolorWithComponentRed:CPTFloat((float)0x09/0xFF)green:CPTFloat((float)0x31/0xFF)blue:CPTFloat((float)0x4A/0xFF)alpha:CPTFloat(1.0)];



 





    int n = 1;



    for ( NSUInteger i =30; i > 0; i--)



    {



        CPTAxisLabel *newLabel = [[CPTAxisLabelalloc] initWithText:@“这里是内容”



                                                          textStyle:textStyleB];



        newLabel.tickLocation =CPTDecimalFromUnsignedInteger(n++);



        newLabel.offset = 5;



        [locationLabels addObject:[NSNumber numberWithFloat:(n-1) -0.25]];



        [locationLabels addObject:[NSNumber numberWithFloat:(n-1) +0.25]];



        [newAxisLabels addObject:newLabel];



        [newLabel release];



    }



    return newAxisLabels;



}

 

//刷新图表内容:

[[bar1graph] reloadData];

 

你可能感兴趣的:(core)