目前我正在使用核心绘图cocoa pod绘制散点图,目前我需要滚动才能启用但,同时我需要x& y轴固定在屏幕的一角,只能以任何方式移动数据吗? 我对以下代码的当前实现使我滚动浏览数据,但当我在图表中滚动很远时,x轴或y轴消失了
-(void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
CPTGraphHostingView* hostView = [[CPTGraphHostingView alloc] initWithFrame:self.view.frame];
[self.view addSubview: hostView];
// Create a CPTGraph object and add to hostView
CPTGraph* graph = [[CPTXYGraph alloc] initWithFrame:hostView.bounds];
hostView.hostedGraph = graph;
// Get the (default) plotspace from the graph so we can set its x/y ranges
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
plotSpace.allowsUserInteraction=YES;
// Note that these CPTPlotRange are defined by START and LENGTH (not START and END) !!
[plotSpace setYRange:[CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:10]]];
[plotSpace setXRange:[CPTPlotRange plotRangeWithLocation:[NSNumber numberWithInt:0] length:[NSNumber numberWithInt:10]]];
plotSpace.delegate = self;
graph.paddingLeft = 10.0;
graph.paddingRight = 10.0;
graph.paddingTop = 10.0;
graph.paddingBottom = 10.0;
// Create the plot (we do not define actual x/y values yet, these will be supplied by the datasource...)
CPTScatterPlot* plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];
// Let's keep it simple and let this class act as datasource (therefore we implemtn <CPTPlotDataSource>)
plot.dataSource = self;
// Finally, add the created plot to the default plot space of the CPTGraph object we created before
[graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
}
提前致谢:)
答案 0 :(得分:1)
使用axisConstraints
:
x.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0.0];
y.axisConstraints = [CPTConstraints constraintWithRelativeOffset:0.0];
使用0.0将轴放置在左侧(y轴)或底部(x轴)。使用1.0将轴放置在右侧(y轴)或顶部(x轴)。 0.0到1.0之间的任何分数都是有效的。