我在iOS 7.1上使用Core Plot 2.0进行简单的X / Y散点图时遇到问题
以下情节代码:
CPTGraphHostingView* graphHostView;
CPTXYGraph* graph;
CPTScatterPlot* plot;
CPTXYPlotSpace* plotSpace;
DebugLog(@"Initializing GRAPH HOST VIEW");
graphHostView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(10, 10, 300, 200)];
[self addSubview: graphHostView];
// Create a CPTGraph object and add to hostView
graph = [[CPTXYGraph alloc] initWithFrame:graphHostView.bounds];
graphHostView.hostedGraph = graph;
// Get the (default) plotspace from the graph so we can set its x/y ranges
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
// Note that these CPTPlotRange are defined by START and LENGTH (not START and END) !!
[plotSpace setYRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( 0 ) length:CPTDecimalFromFloat( 20000 )]];
[plotSpace setXRange: [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat( 0 ) length:CPTDecimalFromFloat( 6 )]];
// Create the plot (we do not define actual x/y values yet, these will be supplied by the datasource...)
plot = [[CPTScatterPlot alloc] initWithFrame:CGRectZero];
plot.dataSource = dataSource;
[graph addPlot:plot toPlotSpace:graph.defaultPlotSpace];
只需60秒即可完成100%CPU使用率的磨削,并可稳定地分配高达300 MB的RAM。怎么可能?该图表托管在“父”UIView中。
之前我使用过Core Plot,虽然看起来很慢,但这显然是完全无法接受的!可能是什么原因造成的?
答案 0 :(得分:0)
我在更新图表时使用dispatch_async解决了这个问题。例如,在我使用的代码中:
dispatch_async(dispatch_get_main_queue(), ^{
[self setupGraph];
});
我希望这会有所帮助。