I am trying to draw a graph on my OS X app and I've successfully drawn the graph and the axes:
The data (looking at the trend) and the y-axis ticks seem to be normal. But as seen above, there are no labels on either axes and there are also no ticks at the X axis.
Here is my code:
graph = [[CPTXYGraph alloc] initWithFrame:self.mainGraph.bounds];
graph.plotAreaFrame.paddingLeft = 50;
graph.plotAreaFrame.paddingBottom = 60;
graph.plotAreaFrame.paddingTop = 10;
graph.plotAreaFrame.paddingRight = 16;
self.mainGraph.hostedGraph = graph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace*)graph.defaultPlotSpace;
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = NSNumberFormatterNoStyle;
NSTimeInterval oneDay = 60 * 60 * 24;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateStyle = NSDateFormatterShortStyle;
CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter];
timeFormatter.multiplier = @(oneDay);
NSDate *refDate = [graphDates firstObject];
timeFormatter.referenceDate = refDate;
CPTXYAxisSet *axisSet = (id)graph.axisSet;
CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
lineStyle.lineColor = [CPTColor grayColor];
lineStyle.lineWidth = 1.0f;
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];
axisSet.yAxis.title = @"Followers";
axisSet.yAxis.titleOffset = 0;
axisSet.yAxis.majorIntervalLength = CPTDecimalFromInt(1000);
axisSet.yAxis.minorTicksPerInterval = 9;
axisSet.yAxis.majorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLineStyle = lineStyle;
axisSet.yAxis.minorTickLength = 4;
axisSet.yAxis.majorTickLength = 10;
axisSet.yAxis.tickDirection = CPTSignNone;
axisSet.yAxis.labelFormatter = numberFormatter;
axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0];
axisSet.xAxis.majorIntervalLength = CPTDecimalFromInt(oneDay * 7);
axisSet.xAxis.minorTicksPerInterval = 6;
axisSet.xAxis.majorTickLineStyle = lineStyle;
axisSet.xAxis.minorTickLineStyle = lineStyle;
axisSet.xAxis.labelFormatter = timeFormatter;
axisSet.xAxis.labelRotation = M_PI / 4;
axisSet.xAxis.majorTickLength = 10;
I've also tried assigning labeling policies, but no avail (best I could get was also losing my Y-axis ticks too).
And on data refresh (including the initial load), after this code:
graphMax = followers * 1.1;
graphMin = 0;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace*)graph.defaultPlotSpace;
NSTimeInterval intervalSpan = [[graphDates lastObject] timeIntervalSinceReferenceDate] - [[graphDates firstObject] timeIntervalSinceReferenceDate];
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0) length:CPTDecimalFromDouble(intervalSpan)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(graphMin) length:CPTDecimalFromInt(graphMax)];
Where graphDates
hold the smallest and the biggest date in a sorted order, which is a few days back and just now respectively in my case.
My graph and my plot area frame have a lot of padding at all sides, so it doesn't seem to be the common padding issue. What else causes labels not to display?
The problem was specific to El Capitan and Core Plot and it was addressed by the framework.