1

我正在尝试制作带有核心图的条形图。我无法正确缩放 y 轴或正确位置的刻度线。我最大的问题是,如果我设置:

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDEcimalFromFloat(0) length:CPTDecimalFromFloat(max_value);

并且 max_value 高于 10 需要不合理的时间来加载图表。例如,我需要 max_value 大约为 1000 以显示所有值的顶部,但是当我将其设置为 1000 时,加载屏幕需要超过 15 秒。但是,如果我将其设置为 10,我的条形图会占据整个屏幕,而您看不到顶部。

这是处理此问题的代码的其余部分。任何意见,将不胜感激。

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
                                                length:CPTDecimalFromFloat(1000)];
[plotSpace scaleToFitPlots:[NSArray  arrayWithObjects:_liftOffPlot,_sideLeanPlot,_forwardLeanPlot,_crossLegsPlot,nil]];
graph.plotAreaFrame.borderLineStyle = nil;


axisSet.yAxis.title = @"times completed";
axisSet.yAxis.titleTextStyle = axisTitleStyle;
axisSet.yAxis.titleOffset = -25.0f;
axisSet.yAxis.axisLineStyle = nil;

axisSet.yAxis.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
axisSet.yAxis.preferredNumberOfMajorTicks = 10;
axisSet.yAxis.minorTicksPerInterval = 1;
axisSet.yAxis.minorTickLocations = nil;
axisSet.yAxis.majorTickLocations = nil;
axisSet.yAxis.title = @"times completed";
axisSet.yAxis.titleTextStyle = axisTitleStyle;
axisSet.yAxis.titleOffset = -25.0f;
axisSet.yAxis.axisLineStyle = nil;

axisSet.yAxis.majorIntervalLength = CPTDecimalFromString(@"100");
axisSet.yAxis.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");

axisSet.yAxis.visibleRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(1000)]; 
axisSet.yAxis.gridLinesRange = axisSet.yAxis.visibleRange;
4

1 回答 1

2

As I seem to be finding with most things xcode, it is all about where you put your code. If I have CPTPlotRange:PlotRangeWithLocation:Length before I do my set up it is really slow and buggy. If instead I add it to the end of my code after setting the other values for the axises suddenly there is only a very minor delay. I actually got this code originally from a tutorial and modified it to fit what I needed but I guess the tutorial didn't have the same delay because the length of the data was much lower.

So all I did to fix this problem was put the following code after my axis set up instead of before;

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0)
                                            length:CPTDecimalFromFloat(1000)];
[plotSpace scaleToFitPlots:[NSArray     arrayWithObjects:_liftOffPlot,_sideLeanPlot,_forwardLeanPlot,_crossLegsPlot,nil]];
graph.plotAreaFrame.borderLineStyle = nil;
于 2013-06-07T23:35:22.273 回答