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

时间:2014-12-04 17:46:37

标签: ios objective-c iphone core-plot

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

 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];

1 个答案:

答案 0 :(得分:0)

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

xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];