Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Andrei,</p> <p>I realize this is an old question but perhaps this is a useful thought to you or others. I wonder if you can do a bit better than just guessing the padding size you need. How about this code snippet:</p> <pre><code>// set up the Y axis float minY = 0; float maxY = 100; // just some max value float tickLength = 10; // just a pleasing value CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(minY) length:CPTDecimalFromFloat(maxY)]; // set up the line style for y axis CPTMutableLineStyle * lineStyle = [CPTLineStyle lineStyle]; lineStyle.lineColor = [CPTColor blackColor]; lineStyle.lineWidth = 2.0f; // just picked a pleasing value // set up the y axis axisSet = [[CPTXYAxisSet alloc]init]; axisSet.yAxis.majorTickLength = tickLength; // Now you can determine the size of the rectangle needed to display axis and labels by getting // the axis font and measureing how many pixels were needed to draw the maximum Y axis label. UIFont * font = [UIFont fontWithName:axisSet.yAxis.labelTextStyle.fontName size:axisSet.yAxis.labelTextStyle.fontSize]; NSString * maxYLabel = [axisSet.xAxis.labelFormatter stringFromNumber:[NSNumber numberWithDouble:plotSpace.yRange.maxLimitDouble] ]; CGSize textSize = [maxYLabel sizeWithFont:font]; // The offset you are looking for can now be computed by: textSize.width + axisSet.yAxis.majorTickLength + axisSet.yAxis.labelOffset; </code></pre> <p>Anyway, I haven't testing the code above but the concept should apply I think...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload