0
我试图动用我的OS X应用程序的图形,我已经成功地绘制图形和轴:核心情节不显示标签(但它显示的图形和细轴)
数据(看趋势)和y轴蜱似乎是正常的。但是如上所见,任一轴上都没有标签,X轴上也没有刻度。
这里是我的代码:
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;
我也试过标签分配政策,但无济于事(最好我能得到也失去了我的Y轴蜱太)。
且将数据刷新(包括初始负载),这个代码后:
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)];
凡graphDates
保持最小,在一个有序最大的日期,也就是现在分别几天就回来,只是在我的情况。
我的图形和我的绘图区框架在各个方面都有很多填充,所以它似乎不是常见的填充问题。还有什么导致标签不显示?
什么是'numberFormatter'和'timeFormatter'?在代码中的这一点它们是否为非null?什么是剧情空间的xRange?什么是'oneDay'? –
@EricSkroch我已经更新了引用。 –
什么是剧情空间的xRange?你使用的是什么版本的OS X? El Capitan测试版上的标签存在问题(请参阅[问题210](https://github.com/core-plot/core-plot/issues/210))。 –