2014-12-04 95 views
0

我正在使用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

回答

0

下面的代碼解決了我的問題:

xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];