【问题标题】:Cannot Remove or Hide Axes from Core Plot, RealTimePlot无法从 Core Plot、RealTimePlot 中移除或隐藏轴
【发布时间】:2014-04-15 14:24:12
【问题描述】:

如标题中所述,我已成功将 CorePlot 添加到我的项目中,并且它按预期工作。除了仍然显示我无法删除或隐藏的轴标签。这是我的 renderInLayer 代码,

-(void)renderInLayer:(CPTGraphHostingView *)layerHostingView withTheme:(CPTTheme *)theme animated:(BOOL)animated
{
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
    CGRect bounds = layerHostingView.bounds;
#else
    CGRect bounds = NSRectToCGRect(layerHostingView.bounds);
#endif

    CPTGraph *graph = [[[CPTXYGraph alloc] initWithFrame:bounds] autorelease];
    [self addGraph:graph toHostingView:layerHostingView];

    graph.plotAreaFrame.paddingTop    = 0.0;
    graph.plotAreaFrame.paddingRight  = 0.0;
    graph.plotAreaFrame.paddingBottom = 0.0;
    graph.plotAreaFrame.paddingLeft   = 0.0;
    graph.plotAreaFrame.masksToBorder = NO;

    // Create the plot
    CPTScatterPlot *dataSourceLinePlot = [[[CPTScatterPlot alloc] init] autorelease];
    dataSourceLinePlot.identifier     = kPlotIdentifier;
    dataSourceLinePlot.cachePrecision = CPTPlotCachePrecisionDouble;

    CPTMutableLineStyle *lineStyle = [[dataSourceLinePlot.dataLineStyle mutableCopy] autorelease];
    lineStyle.lineWidth              = 3.0;
    lineStyle.lineColor              = [CPTColor whiteColor];
    dataSourceLinePlot.dataLineStyle = lineStyle;

    dataSourceLinePlot.dataSource = self;
    dataSourceLinePlot.interpolation = CPTScatterPlotInterpolationCurved;
    [graph addPlot:dataSourceLinePlot];

    // Plot space
    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(kMaxDataPoints - 2)];
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(1)];

    [dataTimer invalidate];
    [dataTimer release];

    if ( animated ) {
        dataTimer = [[NSTimer timerWithTimeInterval:1.0 / kFrameRate
                                             target:self
                                           selector:@selector(newData:)
                                           userInfo:nil
                                            repeats:YES] retain];
        [[NSRunLoop mainRunLoop] addTimer:dataTimer forMode:NSRunLoopCommonModes];
    }
    else {
        dataTimer = nil;
    }
}

用不良数据可视化,

编辑

我试过了,但是没用,

 CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
 CPTXYAxis *axis          = axisSet.xAxis;

 axis.hidden = YES;
 for (CPTAxisLabel *axisLabel in axis.axisLabels) {
      axisLabel.contentLayer.hidden = YES;
 }

【问题讨论】:

    标签: ios objective-c core-graphics core-animation core-plot


    【解决方案1】:

    好的,所以我自己找到了答案。如果将来有人想删除标签。那么请这样做,

    axis.labelingPolicy = CPTAxisLabelingPolicyNone;
    

    如果你想完全删除图形的轴,那么。

    graph.axisSet = nil;
    

    繁荣都过去了,你现在有清晰漂亮的图表:)

    【讨论】:

      【解决方案2】:

      您可以简单地隐藏所有标签。

      CPTAxis *axis = xAxis;
      
      axis.hidden = YES;
      for (CPTAxisLabel *axisLabel in axis.axisLabels) {
          axisLabel.contentLayer.hidden = YES;
      }
      

      我正在发布我如何自定义我的 xAxis 标签:

      CPTXYAxisSet *axisSet = (CPTXYAxisSet *)_graph.axisSet;
      CPTXYAxis *x          = axisSet.xAxis;
      x.majorIntervalLength         = CPTDecimalFromString(@"5");
      x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
      x.minorTicksPerInterval       = 4;
      x.title = @"";
      x.titleTextStyle = axisTitleStyle;
      x.labelingPolicy = CPTAxisLabelingPolicyNone; //No labels provided; user sets labels and tick locations.
      //x.majorTickLineStyle = axisLineStyle;
      x.majorTickLength = 5.0f;
      x.tickDirection = CPTSignNegative;
      
      CPTMutableTextStyle *axisLabelStyle = [CPTMutableTextStyle textStyle];
      axisLabelStyle.fontName = @"Helvetica Neue Thin";
      axisLabelStyle.fontSize = 8.0f;
      NSArray *lastThirtyDates = [self.analyticsDataController lastThirtyDays];
      NSUInteger daysCount = 31;
      NSMutableSet *xLabels = [NSMutableSet setWithCapacity:daysCount];
      NSMutableSet *xLocations = [NSMutableSet setWithCapacity:daysCount];
      NSMutableSet *xMinorLocations = [NSMutableSet setWithCapacity:daysCount];
      
      for (//iterate over your data source for x values and create your custom labels) {
              CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:@"" textStyle:axisLabelStyle];
              CGFloat location = i;
              label.tickLocation = CPTDecimalFromCGFloat(location);
              label.offset = x.majorTickLength;
              if (label) {
                  [xLabels addObject:label];
                  [xLocations addObject:[NSNumber numberWithFloat:location]];
              }
      }
      
      x.axisLabels = xLabels;
      x.majorTickLocations = xLocations;
      x.minorTickLocations = xMinorLocations;
      

      【讨论】:

      • 试过了,但也没有用。请检查我编辑的有问题的新代码。谢谢
      • @doNotCheckMyBlog 请调试并检查您的axisLabel是否不为零。
      • 我实际上通过调整一些东西找到了答案。 axis.labelingPolicy = CPTAxisLabelingPolicyNone 删除标签。但是它仍然保留那些 x 和 y 线。我只想绘制隐藏或删除的所有其他内容:) 但再次感谢
      • @doNotCheckMyBlog 啊,我也刚刚发布了该政策 :) 抱歉没有从一开始就发布。先生,编码愉快!
      • Core-Plot 的实时图形性能让我感到惊讶...感谢 Neil
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 2015-02-26
      • 1970-01-01
      • 2020-02-16
      相关资源
      最近更新 更多