gpt4 book ai didi

ios - Core-Plot iOS - 仅每隔一秒图表显示一次将多个图表添加到屏幕

转载 作者:行者123 更新时间:2023-11-29 13:37:41 25 4
gpt4 key购买 nike

我有一个包含 6 个 UIView 的父 View ,我向其中添加了我的核心绘图图表(这工作正常,但由于某种原因仅每隔一秒钟显示一次图表!)

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
if(!chartVC1){
chartVC1 = [[ChartVC alloc] initWithIdentifier:@"plot1"];
//[chartVC1 setKPlotIdentifier:@"plot1"];
[chartVC1.view setFrame:self.Panel1.frame];
}
[self.Panel1 addSubview:chartVC1.view];

if(!chartVC3){
chartVC3 = [[ChartVC alloc] initWithIdentifier:@"plot2"];
[chartVC3.view setFrame:self.Panel3.frame];
}
[self.Panel3 addSubview:chartVC3.view];

if(!chartVC2){
chartVC2 = [[ChartVC alloc] initWithIdentifier:@"plot3"];
[chartVC2.view setFrame:self.Panel2.frame];
}

[self.Panel2 addSubview:chartVC2.view];

if(!chartVC4){
chartVC4 = [[ChartVC alloc] initWithIdentifier:@"plot4"];
[chartVC4.view setFrame:self.Panel4.frame];
}
[self.Panel4 addSubview:chartVC4.view];

if(!chartVC5){
chartVC5 = [[ChartVC alloc] initWithIdentifier:@"plot5"];
[chartVC5.view setFrame:self.Panel5.frame];

}
[self.Panel5 addSubview:chartVC5.view];

if(!chartVC6){
chartVC6 = [[ChartVC alloc] initWithIdentifier:@"plot6"];
[chartVC6.view setFrame:self.Panel6.frame];
}
[self.Panel6 addSubview:chartVC6.view];
}

这是我为类 ChartVC 编写的一些代码

-(void)renderInLayer{ CPTXYGraph *graph = [[[CPTXYGraph alloc] initWithFrame:self.view.bounds] autorelease];

[self addGraph:graph toHostingView:self.view];
[self applyTheme:nil toGraph:graph withDefault:[CPTTheme themeNamed:kCPTDarkGradientTheme]];

//[self setTitleDefaultsForGraph:graph withBounds:self.view.bounds];
//[self setPaddingDefaultsForGraph:graph withBounds:self.view.bounds];

graph.plotAreaFrame.paddingTop = -20.0;
graph.plotAreaFrame.paddingRight = -20.0;
graph.plotAreaFrame.paddingBottom = -20.0;
graph.plotAreaFrame.paddingLeft = -20.0;

graph.plotAreaFrame.plotArea.frame = self.view.bounds;

graph.backgroundColor = [[UIColor whiteColor] CGColor];
// Grid line styles
CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
majorGridLineStyle.lineWidth = 0.75;
majorGridLineStyle.lineColor = [[CPTColor colorWithGenericGray:0.2] colorWithAlphaComponent:0.75];

CPTMutableLineStyle *minorGridLineStyle = [CPTMutableLineStyle lineStyle];
minorGridLineStyle.lineWidth = 0.25;
minorGridLineStyle.lineColor = [[CPTColor whiteColor] colorWithAlphaComponent:0.1];

// Axes
// X axis
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
CPTXYAxis *x = axisSet.xAxis;
x.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
x.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
x.majorGridLineStyle = majorGridLineStyle;
x.minorGridLineStyle = minorGridLineStyle;
x.minorTicksPerInterval = 9;
//x.title = @"X Axis";
//x.titleOffset = 35.0;
NSNumberFormatter *labelFormatter = [[NSNumberFormatter alloc] init];
labelFormatter.numberStyle = NSNumberFormatterNoStyle;
x.labelFormatter = labelFormatter;
[labelFormatter release];

// Y axis
CPTXYAxis *y = axisSet.yAxis;
y.labelingPolicy = CPTAxisLabelingPolicyAutomatic;
y.orthogonalCoordinateDecimal = CPTDecimalFromUnsignedInteger(0);
y.majorGridLineStyle = majorGridLineStyle;
y.minorGridLineStyle = minorGridLineStyle;
y.minorTicksPerInterval = 3;
//y.labelOffset = 5.0;
//y.title = @"Y Axis";
//y.titleOffset = 30.0;
y.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];

// Rotate the labels by 45 degrees, just to show it can be done.
x.labelRotation = M_PI * 0.25;

// Create the plot
CPTScatterPlot *dataSourceLinePlot1 = [[[CPTScatterPlot alloc] init] autorelease];
dataSourceLinePlot1.identifier = [self kPlotIdentifier];
//NSLog(@"set identifier: %@", [self kPlotIdentifier]);
dataSourceLinePlot1.cachePrecision = CPTPlotCachePrecisionDouble;

CPTMutableLineStyle *lineStyle1 = [[dataSourceLinePlot1.dataLineStyle mutableCopy] autorelease];
lineStyle1.lineWidth = 1.0;
lineStyle1.lineColor = [CPTColor redColor];
dataSourceLinePlot1.dataLineStyle = lineStyle1;

dataSourceLinePlot1.dataSource = self;
[graph addPlot:dataSourceLinePlot1];

// Plot space
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(kMaxDataPoints - 1)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(0) length:CPTDecimalFromUnsignedInteger(100)];

}

如果只显示第一个图表,我会认为问题是我自己的错,但因为每隔一个图表显示它对我来说没有任何意义..

我唯一的猜测是这是某种时间问题,但我对其进行了调试并延迟了每个图表的创建,但没有任何区别。

我什至删除了第 3、5 个图表以查看其他图表现在是否呈现,但之前未显示的相同 3 个图表仍然不可见,这真的让我失望了..(即只有第一个图表显示在4 个启用!)

非常感谢任何帮助...

我可能只使用 Apple Developer Library 中的代码来呈现加速度计数据,因为它非常轻量级,一次可以毫无问题地在屏幕上支持 6 个图表...

Core-Plot 似乎不能胜任我猜想的任务......

最佳答案

您没有说哪些图表没有显示,但由于它们总是相同的,我怀疑 View 层次结构存在问题。尝试改变

`[chartVC1.view setFrame:self.Panel1.frame];`

`[chartVC1.view setFrame:self.Panel1.bounds];`

对于每个图表。

关于ios - Core-Plot iOS - 仅每隔一秒图表显示一次将多个图表添加到屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10086722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com