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))。 –