为什么我的X轴在iPhone上不显示核心图? [英] Why won't my x-axis show with core-plot on the iPhone?

查看:212
本文介绍了为什么我的X轴在iPhone上不显示核心图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我认为我的问题更好地表述为:我如何可以有一个Y轴不从零开始?看起来x轴总是位于y = 0处,但我希望x轴在y轴上处于某个正数。

这里是一个更常见的数据图...我只是希望x轴放置在绘图的最小y值(约77),而不是0。

这是我用来创建图形的函数。

Here is the function I use to create the graph.

这是一大堆代码,我不太确定哪个部分可能关闭以不显示x轴。

It's a whole bunch of code, and I'm not quite sure which piece might be off to not display the x-axis.

x轴不显示与我的资料有关吗?

Could the x-axis not showing have something to do with my data?

- (void) showGraph:(SavedDetailScreen*)dataSource {

  // create the graph and add it to the view
  CPXYGraph *graph = [[CPXYGraph alloc] initWithFrame: CGRectZero];
  graph.plotArea.masksToBorder = NO;
  CPLayerHostingView *graphView = [[CPLayerHostingView alloc] initWithFrame:CGRectMake(0,0, 280, 240)];
  [self addSubview:graphView];
  graphView.hostedLayer = graph;
  graph.paddingLeft = 50.0;
  graph.paddingTop = 20.0;
  graph.paddingRight = 10.0;
  graph.paddingBottom = 40.0;              

  // set up the ranges for the graph axis
  float minElevation = dataSource.track.tbStats.minAlt;
  float maxElevation = dataSource.track.tbStats.maxAlt-dataSource.track.tbStats.minAlt;
  float minDistance = 0.0f;
  float maxDistance = dataSource.track.tbStats.totalDistance;
  CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
  plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minDistance)
                                             length:CPDecimalFromFloat(maxDistance)];
  plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minElevation)
                                                 length:CPDecimalFromFloat(maxElevation)];

  // style the graph with white text and lines
  CPTextStyle *whiteText = [CPTextStyle textStyle];
  whiteText.color = [CPColor whiteColor];              
  CPLineStyle *whiteStyle = [CPLineStyle lineStyle];
  whiteStyle.lineColor = [CPColor whiteColor];
  whiteStyle.lineWidth = 2.0f;

  // set up the axis
  CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;      
  CPXYAxis *x = axisSet.xAxis;
  CPXYAxis *y = axisSet.yAxis;              
  x.majorIntervalLength = CPDecimalFromFloat(maxDistance/10.0f);
  x.minorTicksPerInterval = 0;
  x.majorTickLineStyle = whiteStyle;
  x.minorTickLineStyle = whiteStyle;
  x.axisLineStyle = whiteStyle;
  x.minorTickLength = 5.0f;
  x.majorTickLength = 10.0f;
  x.labelOffset = 3.0f;
  x.labelTextStyle = whiteText;
  y.majorIntervalLength = CPDecimalFromFloat(maxElevation/5.0f);
  y.minorTicksPerInterval = 0;
  y.majorTickLineStyle = whiteStyle;
  y.minorTickLineStyle = whiteStyle;
  y.axisLineStyle = whiteStyle;
  y.minorTickLength = 5.0f;
  y.majorTickLength = 10.0f;
  y.labelOffset = 3.0f;
  y.labelTextStyle = whiteText;

  CPScatterPlot *plot = [[[CPScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
  plot.dataLineStyle.lineWidth = 2.0f;
  plot.dataLineStyle.lineColor = [CPColor blueColor];
  plot.dataSource = dataSource;
  [graph addPlot:plot];
  CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
  greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
  greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
  plot.plotSymbol = greenCirclePlotSymbol;                 

}

推荐答案

您设置轴的位置在正交轴上使用轴的constantCoordinateValue属性。只需将x轴上的属性设置为正值y,轴就会向上移动。

You set the position of an axis on the orthogonal axis using the constantCoordinateValue property of the axis. Just set that property on the x axis to a positive value of y, and the axis should move up.

这篇关于为什么我的X轴在iPhone上不显示核心图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆