我正在尝试设置一个在正象限中启用滚动的图表。这里的问题是滚动图形开始与y轴标签重叠!如下面的截图所示。任何帮助将非常感激。我使用以下代码来设置绘图的全局范围。
plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat([xAxisPlots count]*2)];
plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(maxValue*GLOBAL_AXIS_RATIO)];
-(void)configureGraph
{
graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
[graph applyTheme:[CPTTheme themeNamed:kCPTPlainWhiteTheme]];
self.hostView.hostedGraph = graph;
graph.plotAreaFrame.borderLineStyle = nil;
[graph setPaddingLeft:5.0f];
// 2 - Set graph title
// NSString *title = graphTitle;
// graph.title = title;
// 3 - Create and set text style
CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
titleStyle.color = [CPTColor whiteColor];
titleStyle.fontName = @"Helvetica-Bold";
titleStyle.fontSize = 16.0f;
graph.titleTextStyle = titleStyle;
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.titleDisplacement = CGPointMake(0.0f, 10.0f);
// 4 - Set padding for plot area
[graph.plotAreaFrame setPaddingLeft:32.0f];
[graph.plotAreaFrame setPaddingBottom:45.0f];
// 5 - Enable user interactions for plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction = YES;
}
,轴图是这样的:
CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
axisTitleStyle.color = [CPTColor whiteColor];
axisTitleStyle.fontName = @"Helvetica-Bold";
axisTitleStyle.fontSize = 12.0f;
CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
axisLineStyle.lineWidth = 2.0f;
axisLineStyle.lineColor = [CPTColor whiteColor];
CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
axisTextStyle.color = [CPTColor whiteColor];
axisTextStyle.fontName = @"Helvetica-Bold";
axisTextStyle.fontSize = 11.0f;
CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor whiteColor];
tickLineStyle.lineWidth = 2.0f;
CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
gridLineStyle.lineColor = [CPTColor whiteColor];
gridLineStyle.lineWidth = 0.5f;
tickLineStyle.lineColor = [CPTColor blackColor];
tickLineStyle.lineWidth = 1.0f;
// 2 - Get axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
// 3 - Configure x-axis
CPTAxis *x = axisSet.xAxis;
axisSet.xAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
x.title = @"Days";
x.titleTextStyle = axisTitleStyle;
x.titleOffset = 25.0f;
x.axisLineStyle = axisLineStyle;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.majorGridLineStyle = gridLineStyle;
x.labelTextStyle = axisTextStyle;
x.majorTickLineStyle = axisLineStyle;
x.majorTickLength = 4.0f;
x.tickDirection = CPTSignNegative;
//4 - Configure y axis
CPTAxis *y = axisSet.yAxis;
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
y.title = yAxisTitle;
y.titleTextStyle = axisTitleStyle;
y.titleOffset = -10.0f;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = gridLineStyle;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelTextStyle = axisTextStyle;
y.labelOffset = 0.0f;
y.majorTickLineStyle = axisLineStyle;
y.majorTickLength = 4.0f;
y.tickDirection = CPTSignPositive;
答案 0 :(得分:0)
您可以停止滚动绘图空间超出负值。 试试这个: CPTXYPlotSpace * plotSpace =(CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.globalYRange = [plotSpace yRange];