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];  
     
  • 相关阅读:
    Strom在本地运行调试出现的错误
    能否通过六面照片构建3D模型?比如人脸,全身的多角度照片,生成3D模型。?
    怎么识别自己的眼型?眼型图片参照
    用opencv检测人眼并定位瞳孔位置
    仿射变换
    二维图像的三角形变换算法解释
    Labeled Faces in the Wild 人脸识别数据集
    【图像处理】计算Haar特征个数
    人脸识别技术大总结(1):Face Detection & Alignment
    基于Policy Gradient实现CartPole
  • 原文地址:https://www.cnblogs.com/mins/p/4597314.html
Copyright © 2011-2022 走看看