问题:使用自动缩放 ( ) 时,我无法让 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 轴正下方(请参阅下面的屏幕截图):)。
谢谢!