1

问题:使用自动缩放 ( ) 时,我无法让 Core Plot (1.1) 为我的x[plotSpace scaleToFitPlots:[graph allPlots]轴绘制自动标签。

我尝试过的:我更改了偏移量和填充的值,但这并没有改变结果。但是,当关闭自动缩放时(不自动使用[plotSpace scaleToFitPlots:[graph allPlots]]和设置y比例, x轴的自动标记起作用。

问题:Core Plot 中是否有错误或我做错了什么?我将不胜感激任何帮助!

谢谢!

这就是我设置图表的方式:

CPTBarPlot *barPlot = [CPTBarPlot 
   tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
barPlot.baseValue       = CPTDecimalFromInt(0);
barPlot.barOffset       = CPTDecimalFromFloat(0.0f); // CPTDecimalFromFloat(0.5f);
barPlot.barWidth        = CPTDecimalFromFloat(0.4f);
barPlot.barCornerRadius = 4;
barPlot.labelOffset = 5;
barPlot.dataSource      = self;
barPlot.delegate        = self;
 
graph = [[CPTXYGraph alloc]initWithFrame:self.view.bounds];
   self.hostView.hostedGraph = graph;
    
graph.paddingLeft   = 40.0f;
graph.paddingTop    = 30.0f;
graph.paddingRight  = 30.0f;
graph.paddingBottom = 50.0f;
        
[graph addPlot:barPlot];
        
graph.plotAreaFrame.masksToBorder = NO;
graph.plotAreaFrame.cornerRadius  = 0.0f;
graph.plotAreaFrame.borderLineStyle = borderLineStyle;
    
double xAxisStart = 0;
CPTXYAxisSet *xyAxisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *xAxis = xyAxisSet.xAxis;
CPTMutableLineStyle *lineStyle = [xAxis.axisLineStyle mutableCopy];
lineStyle.lineCap = kCGLineCapButt;
xAxis.axisLineStyle = lineStyle;
xAxis.majorTickLength = 10;
xAxis.orthogonalCoordinateDecimal   = CPTDecimalFromDouble(yAxisStart);
xAxis.paddingBottom = 5;
        
xyAxisSet.delegate = self;
xAxis.delegate = self;
xAxis.labelOffset = 0;
         
xAxis.labelingPolicy = CPTAxisLabelingPolicyAutomatic;

[plotSpace scaleToFitPlots:[graph allPlots]];
        
CPTMutablePlotRange *yRange = plotSpace.yRange.mutableCopy;
[yRange expandRangeByFactor:CPTDecimalFromDouble(1.3)];
plotSpace.yRange = yRange;
NSInteger xLength = CPTDecimalIntegerValue(plotSpace.xRange.length) + 1;
        
plotSpace.xRange = [CPTPlotRange
plotRangeWithLocation:CPTDecimalFromDouble(xAxisStart) 
   length:CPTDecimalFromDouble(xLength)] ;

编辑

埃里克的回答有所帮助。现在绘制了 x 标签,但在错误的 y 位置(偏移)。如何将它们绘制在 x 轴正下方(请参阅下面的屏幕截图):)在此处输入图像描述在此处输入图像描述

谢谢!

4

2 回答 2

4

在缩放绘图空间后设置orthogonalCoordinateDecimal轴。只是猜测,但yAxisStart用于定位 x 轴的值可能超出缩放范围。

于 2012-12-02T17:01:40.617 回答
0

我遇到了同样的问题,并通过在 (-1,-1) 的 (x,y) 值处添加另一个带有 lineWidth:0.0 和 clearColor 的图来修补它。scaleToFit 包含此图并显示我的标签和轴。

于 2015-08-30T15:43:47.407 回答