zoukankan      html  css  js  c++  java
  • [转载]core-Plot学习二 自定义CorePlot label及majorGridLine莫名其妙消失的Bug

    设置corePlot可拖动: 

    plotSpace.allowsUserInteraction = YES;  

    设置x显示的范围:

    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(8 * oneDay)length:CPTDecimalFromInt(23 * oneDay)];  

    设置x轴拖动范围:

    plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(31 * oneDay)];  

    禁止corePlot缩放(Self是CPTGraphHostingView):

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

    自定义label:

        x.axisLabels = [self buildLabelTitle];  
        x.labelingPolicy = CPTAxisLabelingPolicyNone;  
          
        //构建30天的label样式  
        - (NSMutableSet*)buildLabelTitle  
        {  
            NSMutableSet *newAxisLabels = [NSMutableSet set];  
              
            CPTMutableTextStyle *textStyleB = [CPTMutableTextStyle textStyle];  
            textStyleB.color = [CPTColor colorWithComponentRed:CPTFloat((float)0x09/0xFF) green:CPTFloat((float)0x31/0xFF) blue:CPTFloat((float)0x4A/0xFF) alpha:CPTFloat(1.0)];  
            NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];  
            [dateFormatter setDateFormat:@"MM.dd"];  
          
            int n = 1;  
            for ( NSUInteger i = 29; i > 0; i--) //从今起前29天  
            {  
                NSTimeInterval secondsPerDay = 24 * 60 * 60 * i;  
                NSDate *ago = [[NSDate alloc] initWithTimeIntervalSinceNow:-secondsPerDay];  
                CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:[dateFormatter stringFromDate:ago]  
                                                                  textStyle:textStyleB];  
                [ago release];  
                newLabel.tickLocation = CPTDecimalFromUnsignedInteger(n++ * oneDay);  
                newLabel.offset = 5;  
                [self.locationLabels addObject:[NSNumber numberWithInt:(n-1) * oneDay]];  
                [newAxisLabels addObject:newLabel];  
                [newLabel release];  
            }  
              
            //今天  
            CPTMutableTextStyle *textStyleW = [CPTMutableTextStyle textStyle];  
            textStyleW.color = [CPTColor whiteColor];  
            CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:@"今日" textStyle:textStyleW];  
            newLabel.tickLocation = CPTDecimalFromUnsignedInteger(oneDay * n);  
            [self.locationLabels addObject:[NSNumber numberWithInt:(n) * oneDay]];  
            newLabel.offset = 5;  
            [newAxisLabels addObject:newLabel];  
            [newLabel release];  
              
            return newAxisLabels;  
        }  
    View Code

    但是写好后发现majorGridLine不见了,之后各种折腾后终于找到原因是:

    CPTAxisLabelingPolicyNone       No labels provided; user sets labels and tick locations.

    设置这个属性是要自己重新定义majorGridLine位置的

    所以需要使用:

        x.majorTickLocations = [NSSet setWithArray:locationLabels];  
     
  • 相关阅读:
    柠檬班软件测试就业班学习笔记持续更新
    linux练习题面试必备持续更新
    windows10 mysql5.7.23解压版安装教程
    2020 年最新:Maven无法使用阿里云仓库下载
    cd1101d 树形dp
    SemanticException [Error 10025]
    spark学习
    es学习
    nginx配置-线上服务器
    jdk、tomcat升级过程中遇到的问题
  • 原文地址:https://www.cnblogs.com/mins/p/4597314.html
Copyright © 2011-2022 走看看