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

在项目需求中。要画一个点线图。横坐标是  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];


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值