在CorePlot中定制显示横轴X的label

来源:互联网 发布:手机安装电视软件 编辑:程序博客网 时间:2024/04/29 18:32

在项目需求中。要画一个点线图。横坐标是  288个数值。代表:每5分钟一个值。每天产生 288个值。

在图表中,只需要显示 4,6,8,10,12,14,16,18,20,22,24 ,这几个整数的label,并且要转换成 文字描述。

参考文章

http://stackoverflow.com/questions/2904562/how-do-you-provide-labels-for-the-axis-of-a-core-plot-chart

注意 这句话:

  x.labelingPolicy = CPTAxisLabelingPolicyNone;

First, you set the axis labeling policy to CPTAxisLabelingPolicyNone to let the framework know you will be providing custom labels, then you create an array of labels with their corresponding locations, and finally you assign that array of labels to the axisLabels property on the X axis.


// 设置X轴label    x.labelingPolicy = CPTAxisLabelingPolicyNone;    NSMutableArray *labelArray=[NSMutableArray arrayWithCapacity:288];    for ( int  i = 1 ; i<=288 ;i++)    {        CPTAxisLabel *newLabel ;        if(i == 48)        {            newLabel=[[CPTAxisLabel alloc] initWithText:@"4点" textStyle:x.labelTextStyle];        }else if (i== 72){            newLabel=[[CPTAxisLabel alloc] initWithText:@"6点" textStyle:x.labelTextStyle];        }else if (i== 96){            newLabel=[[CPTAxisLabel alloc] initWithText:@"8点" textStyle:x.labelTextStyle];        }else if (i== 120){            newLabel=[[CPTAxisLabel alloc] initWithText:@"10点" textStyle:x.labelTextStyle];        }else if (i== 144){            newLabel=[[CPTAxisLabel alloc] initWithText:@"12点" textStyle:x.labelTextStyle];        }else if (i== 168){            newLabel=[[CPTAxisLabel alloc] initWithText:@"14点" textStyle:x.labelTextStyle];        }else if (i== 192){            newLabel=[[CPTAxisLabel alloc] initWithText:@"16点" textStyle:x.labelTextStyle];        }else if (i== 216){            newLabel=[[CPTAxisLabel alloc] initWithText:@"18点" textStyle:x.labelTextStyle];        }else if (i== 240){            newLabel=[[CPTAxisLabel alloc] initWithText:@"20点" textStyle:x.labelTextStyle];        }else if (i== 264){            newLabel=[[CPTAxisLabel alloc] initWithText:@"22点" textStyle:x.labelTextStyle];        }else if (i== 288){            newLabel=[[CPTAxisLabel alloc] initWithText:@"24点" textStyle:x.labelTextStyle];        }        else{            newLabel=[[CPTAxisLabel alloc] initWithText:@"" textStyle:x.labelTextStyle];        }        newLabel.tickLocation=[[NSNumber numberWithInt:i] decimalValue];        newLabel.offset=x.labelOffset+x.majorTickLength;        [labelArray addObject:newLabel];        [newLabel release];    }    x.title = @"时间";    x.axisLabels=[NSSet setWithArray:labelArray];


原创粉丝点击