当前位置: 首页 > 工具软件 > Core-Plot > 使用案例 >

IOS绘图控件Core-plot学习笔记

澹台展鹏
2023-12-01

一、改变X轴的标签

        默认的情况下X轴的标签是Decimal类型,需用通过CPTAxisLabel来配置相应的标签集合.

       1)需要设置标签的Policy,否则无论怎么设置AxisLabel都不会启动作用,x.labelingPolicy = CPTAxisLabelingPolicyNone,一共下面五个配置选项:

             CPTAxisLabelingPolicyNone                             No labels provided; user sets labels and tick locations.
             CPTAxisLabelingPolicyLocationsProvided     User sets tick locations; axis makes labels.
             CPTAxisLabelingPolicyFixedInterval                 Fixed interval labeling policy.
             CPTAxisLabelingPolicyAutomatic                      Automatic labeling policy.
             CPTAxisLabelingPolicyEqualDivisions            Divide the plot range into equal parts.

          2)配置相应的标签选项

              NSArray *xAxisLabels         = [NSArray arrayWithObjects:@"Label A", @"Label B", @"Label C", @"Label D", @"Label E", nil];
              NSUInteger labelLocation     = 0;
              NSMutableArray * locationLabels = [[NSMutableArray alloc]init];
              NSMutableArray *customLabels  = [[NSMutableArray alloc]init];
              for ( NSString * text in xAxisLabels ) {
                        CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:text  textStyle:x.labelTextStyle];
                        newLabel.tickLocation = CPTDecimalFromInt(labelLocation++);
                        newLabel.offset       =   x.majorTickLength;
                        newLabel.rotation = M_PI/8;
                        [customLabels addObject:newLabel];
                        [newLabel release];
                       [locationLabels addObject:[NSNumber numberWithInt:labelLocation ]];
               }
             x.majorTickLocations = [NSSet setWithArray:locationLabels];
             [locationLabels release];
             x.axisLabels = [NSSet setWithArray:customLabels];

             [customLabels release];


 类似资料: