xAxis标题和标签不会出现在CorePlot中

问题描述:

我正在使用CorePlot在图表上显示一些数据。 y轴标题和标签显示没有问题,但即使使用自动标签策略,x轴的标题和刻度标签也不会显示。请帮帮我。xAxis标题和标签不会出现在CorePlot中

CPTMutableLineStyle *whiteLineStyle = [CPTMutableLineStyle lineStyle]; 
    whiteLineStyle.lineColor = [CPTColor whiteColor]; 
    whiteLineStyle.lineWidth = 1.0; 

    CPTXYGraph *newGraph = [[CPTXYGraph alloc] initWithFrame:self.view.bounds]; 
    newGraph.paddingRight = 50; 
    newGraph.paddingLeft = 50; 
    newGraph.paddingTop = 10; 
    newGraph.paddingBottom = 40; 
    newGraph.plotAreaFrame.paddingBottom = 40; 
    newGraph.plotAreaFrame.masksToBorder = NO; 
    newGraph.plotAreaFrame.borderLineStyle = nil; 

    self.graphHost.hostedGraph = newGraph; 

    CPTTheme *theme = [CPTTheme themeNamed:kCPTSlateTheme]; 
    [newGraph applyTheme:theme]; 

    CPTXYAxisSet *xyAxisSet= (CPTXYAxisSet *)newGraph.axisSet; 
    CPTXYAxis *xAxis = xyAxisSet.xAxis; 
    CPTXYAxis *yAxis = xyAxisSet.yAxis; 

    xAxis.title = @"Date/Time"; 
    yAxis.title = @"Trading Range"; 

    [xAxis setLabelingPolicy:CPTAxisLabelingPolicyNone]; 
    xAxis.majorTickLocations = [self majorTickLocations]; 
    [xAxis setAxisLabels:[NSSet setWithArray:[self getXAxisTitleArray]]]; 
    xAxis.majorTickLineStyle = whiteLineStyle; 



    [yAxis setLabelingPolicy:CPTAxisLabelingPolicyAutomatic]; 

    CPTTradingRangePlot *ohlcPlot = [[CPTTradingRangePlot alloc] initWithFrame:newGraph.bounds]; 
    ohlcPlot.labelOffset = 10.0; 
    ohlcPlot.stickLength = 10.0; 
    ohlcPlot.dataSource = self; 
    ohlcPlot.plotStyle = CPTTradingRangePlotStyleCandleStick; 
    ohlcPlot.lineStyle = whiteLineStyle; 

    CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle]; 
    whiteTextStyle.color = [CPTColor whiteColor]; 
    whiteTextStyle.fontSize = 10.0; 
    ohlcPlot.labelTextStyle = whiteTextStyle; 

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) newGraph.defaultPlotSpace; 
    [newGraph addPlot:ohlcPlot toPlotSpace:plotSpace]; 
+0

也许他们被切断;为'paddingBottom'尝试较小的值。 – Koen 2014-12-04 17:53:34

+0

尝试过了,没有运气:( – rustylepord 2014-12-04 17:58:59

+0

)您可能需要*较大的底部填充和/或较小的标签和标题偏移量,并且检查文本样式如果不使用与工作的y轴标签相同的标签,试试暂时作为测试 – 2014-12-05 01:02:41

下面的代码解决了我的问题:

xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];