Why won't my x-axis show with core-plot on the iPhone?

EDIT: I think my question is better phrased as: How can I have a Y-axis that doesn't start at zero? It seems like the x-axis always gets placed at the y=0, but I would like the x-axis to be at some positive number on the y-axis.

Here's a graph with more regular data... I just wish the x-axis was placed at the minimum y-value for the plot (about 77), instead of at 0.

alt text

Here is the function I use to create the graph.

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

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;                 

}

alt text

This question and answers originated from www.stackoverflow.com
Question by (1/13/2010 5:51:32 AM)

Answer

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.

Answer by

Find More Answers
Related Topics  iphone  objective-c  cocoa-touch  core-plot
Related Questions
  • Date on x axis iphone using core plot

    I want to show data on x-axis on CPXYPlotSpace. I have seen doing so on mac using something like that but it does not work on iphone so any suggestion or i have to do it manually. NSDateFormatte…
  • iPhone Core-Plot Tick Marks Not Showing

    I went through the tutorial here: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application , and I can get a graph to show, but I don't see any tick marks or labels on my ax…
  • Using core plot for iPhone, drawing date on x axis

    I have available an array of dictionary that contains NSDate and NSNumber values. I wanted to plot date on X axis. for plotting I need to supply xRanges to plot with some decimal values.I don't unde…
  • How to scale on x-axis with Core Plot

    I have a barchart display the smoking counter, day by day. Each column represents one day. I would like to view the data on week, month, year, on the same graph by drag on the X-Axis. If I drag the …
  • Core plot with month on x Axis (iphone)

    I would like to draw an XY graph using coreplot on iphone with date on x axis and some values on y axis. Referring to the DatePlot example shipping with the coreplot SDK, I was able to draw graph wi…
  • Core-plot Question : How to add a data Indicator

    i want to add a data indicator line similar to the following image in core-plot. Any idea how i can achieve this using core-plot. I have just started to understand core-plot, so any tip will …
  • CORE PLOT add one more Graph in Vertical BarChart

    Hi I want to make bar chart as shown here I want to plot graph using coreplot example : (coreplot gallery- Vertical Bar Chart) Currently default code plots the graph as shown below …
  • Numbers on axis not showing when using Core Plot

    I'm making a graph for my iOS app, using the Core Plot library However my axes aren't showing any numbers or labels: Here is my viewDidLoad method: - (void)viewDidLoad { [super viewDi…
  • Core Plot: Axis titles show randomly, not always working

    I am trying to get my X and Y axis titles to show, but it seems they are not always working: CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; CPXYAxis *x = axisSet.xAxis; x.orthogonalCoor…
  • Why am I seeing the following linker errors when building an iPhone app with Core Plot?

    When building an iPhone app that uses the Core Plot framework, I am seeing the following linker errors: ld: warning: ignoring file /Users/taxtmart5/Library/Developer/Xcode/DerivedData/Solagen_Cal…