【问题标题】:iPhone Core-Plot Tick Marks Not ShowingiPhone Core-Plot 刻度线不显示
【发布时间】:2009-11-17 22:50:18
【问题描述】:

我在这里完成了教程:http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application,我可以得到一个图表来显示,但我在我的轴集上看不到任何刻度线或标签。我忽略了一些简单的事情吗?下面是我创建图表的代码,我还实现了委托函数。我看到的是坐标轴和绘图,但不是坐标轴刻度线或标签。

感谢您提供的任何帮助。

- (void) showGraph {

  graph = [[CPXYGraph alloc] initWithFrame: CGRectMake(0,0, 320, 320)];

  CPLayerHostingView *graphView = [[CPLayerHostingView alloc] initWithFrame:CGRectMake(0,0, 320, 320)];
  graphView.backgroundColor = [UIColor blueColor];

  AppDelegate *t = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  [t.mapVC.view addSubview:graphView];

  graphView.hostedLayer = graph;
  graph.paddingLeft = 20.0;
  graph.paddingTop = 20.0;
  graph.paddingRight = 20.0;
  graph.paddingBottom = 20.0;

  float minElevation = 0;
  float maxElevation = 10;
  float minTime = 0;
  float maxTime = 5;

  CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
  plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minTime)
                                                 length:CPDecimalFromFloat(maxTime)];
  plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minElevation)
                                                 length:CPDecimalFromFloat(maxElevation)];

  CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;

  CPLineStyle *blackStyle = [CPLineStyle lineStyle];
  blackStyle.lineColor = [CPColor blackColor];
  blackStyle.lineWidth = 5.0f;
  CPLineStyle *whiteStyle = [CPLineStyle lineStyle];
  whiteStyle.lineColor = [CPColor whiteColor];
  whiteStyle.lineWidth = 5.0f;

  axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"]decimalValue];

  axisSet.xAxis.minorTicksPerInterval = 4;
  axisSet.xAxis.majorTickLineStyle = whiteStyle;
  axisSet.xAxis.minorTickLineStyle = whiteStyle;
  axisSet.xAxis.axisLineStyle = blackStyle;
  axisSet.xAxis.minorTickLength = 5.0f;
  axisSet.xAxis.majorTickLength = 10.0f;
  axisSet.xAxis.labelOffset = 3.0f;

  axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"]decimalValue];
  axisSet.yAxis.minorTicksPerInterval = 4;
  axisSet.yAxis.majorTickLineStyle = blackStyle;
  axisSet.yAxis.minorTickLineStyle = blackStyle;
  axisSet.yAxis.axisLineStyle = whiteStyle;
  axisSet.yAxis.minorTickLength = 5.0f;
  axisSet.yAxis.majorTickLength = 10.0f;
  axisSet.yAxis.labelOffset = 3.0f;

  CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc]
                                  initWithFrame:graph.bounds] autorelease];
  xSquaredPlot.identifier = @"X Squared Plot";
  xSquaredPlot.dataLineStyle.lineWidth = 2.0f;
  xSquaredPlot.dataLineStyle.lineColor = [CPColor greenColor];
  xSquaredPlot.dataSource = self;
  [graph addPlot:xSquaredPlot];

  CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
  greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
  greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);

  xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
}

【问题讨论】:

    标签: iphone objective-c cocoa-touch core-plot


    【解决方案1】:

    您需要在轴外侧留出一些空间。 Core Plot 尚未自动为您执行此操作。

    尝试为graph.plotArea.plotGroupgraph.plotArea.axisSet 添加一些填充。有关示例,请参见 iPhone 测试应用程序中的条形图。

    【讨论】:

    • 是的,不幸的是,自该教程发布以来,库中的 API 发生了一些变化。我们尝试维护示例应用程序以展示与库交互的正确方式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多