I am using CorePlot for the iPhone. I can do a simple graph just fine. But what I'm looking to do is to have the y-axis go from 0-100 and the x-axis go from 1998 - 2007. I'd like to keep this numerical (not custom text based labels) if possible.
The issue, is that when you set up these axis:
// We modify the graph's plot space to setup the axis' min / max values.
float xAxisMin = 1998
float xAxisMax = 2007;
float yAxisMin = 0;
float yAxisMax = 100;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(xAxisMin) length:CPTDecimalFromFloat(xAxisMax - xAxisMin)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(yAxisMin) length:CPTDecimalFromFloat(yAxisMax - yAxisMin)];
// Modify the graph's axis with a label, line style, etc.
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
axisSet.xAxis.title = @"";
axisSet.xAxis.titleTextStyle = textStyle;
axisSet.xAxis.titleOffset = 10.0f;
axisSet.xAxis.axisLineStyle = lineStyle;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.labelTextStyle = textStyle;
axisSet.xAxis.majorIntervalLength = CPTDecimalFromFloat(1000.0f);
axisSet.xAxis.labelOffset = 1.0f;
axisSet.xAxis.minorTicksPerInterval = 1;
axisSet.xAxis.minorTickLength = 5.0f;
axisSet.xAxis.majorTickLength = 7.0f;
You get a graph that shows the y-axis at 0 going to 100 then the xaxis starts at about 1998 to the right. i.e. they graph does not cross at X: 1998 y: 0. Is there a way to force it to do so? As far as I can tell I have to do a graph with x-axix range from 0-2007 and y-axis range 0-100. Then can I tell it to cut out the 0-1997 piece and shift so that piece is at 0?
The alternative is to use custom points. Which I tried. But is seems there is a problem where it doesn't show ticks on the graph line. For example if I follow the example in from the source, I can see 1998, 1999, 2000, etc but no | lines cross the x-axis. It's like the tick lines will not draw because I'm using custom lines.
Thanks for any and all help,
-David
Use the orthogonalCoordinateDecimal property:
axisSet.xAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(yAxisMin);
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromFloat(xAxisMin);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With