- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在同一张图上使用 4 个单独的图来绘制 4 channel 输入流的实时图。目前我正在从文本文件中获取这些数据,但最终会使用蓝牙获取这些数据。我的情节本身工作正常,但核心情节似乎在第一个数据集级别的绘图开始时为每个情节绘制了一条额外的水平线。我认为这与 core-plot 试图在开始显示之前绘制所有点有关。下图显示了这些线,而实际波形,方波,正在绘制中。
随着绘图的进行和 x 轴显示范围的变化,这些线会消失。就像在这里:
以下是我的代码的相关部分。它基于 Ray Wenderlich 的散点图教程和 Eric Skrooch 的实时绘图示例。 (我希望我拼对了这些名字!)。就我个人而言,我认为这是核心情节中的错误,而不是编码错误。非常感谢任何有关如何摆脱这些令人不安的线条的帮助!谢谢!
-(void)configurePlots {
//Get graph and plot space
CPTGraph *graph = self.hostView.hostedGraph;
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
//Create the four plots
CPTScatterPlot *channel1Plot = [[CPTScatterPlot alloc]init];
channel1Plot.dataSource = self;
channel1Plot.identifier = @"channel1";
[graph addPlot:channel1Plot toPlotSpace:plotSpace];
CPTScatterPlot *channel2Plot = [[CPTScatterPlot alloc]init];
channel2Plot.dataSource = self;
channel2Plot.identifier = @"channel2";
[graph addPlot:channel2Plot toPlotSpace:plotSpace];
CPTScatterPlot *channel3Plot = [[CPTScatterPlot alloc]init];
channel3Plot.dataSource = self;
channel3Plot.identifier = @"channel3";
[graph addPlot:channel3Plot toPlotSpace:plotSpace];
CPTScatterPlot *channel4Plot = [[CPTScatterPlot alloc]init];
channel4Plot.dataSource = self;
channel4Plot.identifier = @"channel4";
[graph addPlot:channel4Plot toPlotSpace:plotSpace];
//Set up plot space
[plotSpace scaleToFitPlots:[NSArray arrayWithObjects:channel1Plot, channel2Plot, channel3Plot, channel4Plot, nil]];
CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
[xRange expandRangeByFactor:CPTDecimalFromCGFloat(1.1f)];
plotSpace.xRange = xRange;
CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
[yRange expandRangeByFactor:CPTDecimalFromCGFloat(1.2f)];
plotSpace.yRange = yRange;
//Create styles and symbols
CPTMutableLineStyle *channelLineStyle = [channel1Plot.dataLineStyle mutableCopy];
channelLineStyle.lineWidth = 1.0;
channelLineStyle.lineColor = [CPTColor redColor];
channel1Plot.dataLineStyle = channelLineStyle;
channel2Plot.dataLineStyle = channelLineStyle;
channel3Plot.dataLineStyle = channelLineStyle;
channel4Plot.dataLineStyle = channelLineStyle;
}
-(void)configureAxes {
//Create styles
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 yellowColor];
axisTextStyle.fontName = @"Helvetica-Bold";
axisTextStyle.fontSize = 11.0f;
CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineWidth = 2.0f;
tickLineStyle.lineColor = [CPTColor yellowColor];
CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
tickLineStyle.lineColor = [CPTColor purpleColor];
tickLineStyle.lineWidth = 1.0f;
//Get axis set
CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
//Configure X-axis
CPTAxis *x = axisSet.xAxis;
x.title = @"Time";
x.titleTextStyle = axisTitleStyle;
x.titleOffset = 15.0f;
x.axisLineStyle = axisLineStyle;
x.labelingPolicy = CPTAxisLabelingPolicyNone;
x.labelTextStyle = axisTextStyle;
x.majorTickLineStyle = axisLineStyle;
x.majorTickLength = 4.0f;
x.tickDirection = CPTSignNegative;
CGFloat pointsCount = POINTS_ON_SCREEN;
NSMutableSet *xLabels = [NSMutableSet setWithCapacity:pointsCount];
NSMutableSet *xLocations = [NSMutableSet setWithCapacity:pointsCount];
NSInteger i=0;
//NSString *loc = [NSString stringWithFormat:@"d",j];
for (NSInteger j=0; j<POINTS_ON_SCREEN; j++) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%ld", (long)j+1] textStyle:x.labelTextStyle];
CGFloat location = i++;
label.tickLocation = CPTDecimalFromCGFloat(location);
label.offset = x.majorTickLength;
if (label) {
[xLabels addObject:label];
[xLocations addObject:[NSNumber numberWithFloat:location]];
}
}
x.axisLabels = xLabels;
x.majorTickLocations = xLocations;
//Configure Y-axis
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithLowerOffset:0.0];
CPTAxis *y = axisSet.yAxis;
y.title = @"Channel outputs";
y.titleTextStyle = axisTitleStyle;
y.titleOffset = -40.0f;
y.axisLineStyle = axisLineStyle;
y.majorGridLineStyle = gridLineStyle;
y.labelingPolicy = CPTAxisLabelingPolicyNone;
y.labelTextStyle = axisTextStyle;
y.labelOffset = 16.0f;
y.majorTickLineStyle = axisLineStyle;
y.majorTickLength = 4.0f;
y.minorTickLength = 2.0f;
y.tickDirection = CPTSignPositive;
CGFloat majorIncrement = 0.0005;
CGFloat minorIncrement = 0.0001;
CGFloat yMax = 0.0040f;
NSMutableSet *yLabels = [NSMutableSet set];
NSMutableSet *yMajorLocations = [NSMutableSet set];
NSMutableSet *yMinorLocations = [NSMutableSet set];
for (CGFloat j = minorIncrement; j<=yMax; j+=minorIncrement) {
j = roundf(j*100000)/100000;
CGFloat mod = j / majorIncrement;
NSInteger modInt = (NSInteger)mod;
CGFloat modMantissa = mod - modInt;
modMantissa = roundf(modMantissa * 100)/100;
if (modMantissa < 0.1 || modMantissa > 0.9) {
CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%.5f", j] textStyle:y.labelTextStyle];
NSDecimal location = CPTDecimalFromCGFloat(j);
//NSNumber *location = [NSNumber numberWithFloat:j];
label.tickLocation = location;
label.offset = -y.majorTickLength -y.labelOffset -9;
//label.offset = 0;
if (label) {
[yLabels addObject:label];
}
[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
} else {
[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@"%f",j]]];
}
}
y.axisLabels = yLabels;
y.majorTickLocations = yMajorLocations;
y.minorTickLocations = yMinorLocations;
}
-(void)createTimer {
NSTimer *dataTimer = [NSTimer timerWithTimeInterval:0.002 target:self selector:@selector(dynamicUpdate:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:dataTimer forMode:NSDefaultRunLoopMode];
}
-(void)dynamicUpdate: (NSTimer *)dataTimer {
CPTGraph *graph = self.hostView.hostedGraph;
CPTPlot *channel1Plot = [graph plotWithIdentifier:@"channel1"];
CPTPlot *channel2Plot = [graph plotWithIdentifier:@"channel2"];
CPTPlot *channel3Plot = [graph plotWithIdentifier:@"channel3"];
CPTPlot *channel4Plot = [graph plotWithIdentifier:@"channel4"];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
if (channel1Plot && channel2Plot && channel3Plot && channel4Plot) {
if ( arrayIndex1 >= POINTS_ON_SCREEN-1
|| arrayIndex2 >= POINTS_ON_SCREEN-1
|| arrayIndex3 >= POINTS_ON_SCREEN-1
|| arrayIndex4 >= POINTS_ON_SCREEN-1) {
[channel1Array removeObjectAtIndex:0];
[channel1Plot deleteDataInIndexRange:NSMakeRange(0, 1)];
[channel2Array removeObjectAtIndex:0];
[channel2Plot deleteDataInIndexRange:NSMakeRange(0, 1)];
[channel3Array removeObjectAtIndex:0];
[channel3Plot deleteDataInIndexRange:NSMakeRange(0, 1)];
[channel4Array removeObjectAtIndex:0];
[channel4Plot deleteDataInIndexRange:NSMakeRange(0, 1)];
}
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromUnsignedInteger(currentIndex >= POINTS_ON_SCREEN ? currentIndex-POINTS_ON_SCREEN +1 : 0) length:CPTDecimalFromUnsignedInteger(POINTS_ON_SCREEN-1)];
currentIndex++;
[channel1Plot insertDataAtIndex:POINTS_ON_SCREEN-1 numberOfRecords:1];
[channel2Plot insertDataAtIndex:POINTS_ON_SCREEN-1 numberOfRecords:1];
[channel3Plot insertDataAtIndex:POINTS_ON_SCREEN-1 numberOfRecords:1];
[channel4Plot insertDataAtIndex:POINTS_ON_SCREEN-1 numberOfRecords:1];
}
}
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
return POINTS_ON_SCREEN;
}
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)idx {
// NSLog(@"Plotting point");
NSNumber *num = nil;
if ([self.activityIndicator isAnimating] == YES) {
[self.activityIndicator stopAnimating];
}
switch (fieldEnum) {
case CPTScatterPlotFieldX:
if (idx < POINTS_ON_SCREEN) {
return [NSNumber numberWithUnsignedInteger:idx + currentIndex - POINTS_ON_SCREEN];
};
break;
case CPTScatterPlotFieldY:
if ([plot.identifier isEqual:@"channel1"]) {
num = [channel1Array objectAtIndex:idx];
arrayIndex1 = idx;
} else if ([plot.identifier isEqual:@"channel2"]) {
num = [channel2Array objectAtIndex:idx];
arrayIndex2 = idx;
} else if ([plot.identifier isEqual:@"channel3"]) {
num = [channel3Array objectAtIndex:idx];
arrayIndex3 = idx;
} else if ([plot.identifier isEqual:@"channel4"]) {
num = [channel4Array objectAtIndex:idx];
arrayIndex4 = idx;
} else {
NSLog(@"data unavailable");
}
break;
default:
NSLog(@"ERROR: trying to plot on unidentified axis");
break;
}
NSString *numString = [NSString stringWithFormat:@"%@", num];
dispatch_async(AddToArrayQ, ^{[self writeData:numString];});
return num;
}
最佳答案
除非我误读了这一点,否则您将从 numberOfRecordsForPlot: 返回一个硬编码值,因此 CorePlot 期望能够填充 x 轴上的所有这些点。您看到的那些行可能是由于将这些数组初始化为常量值(它们必须被初始化,对吧,否则当您尝试访问未初始化的索引时会出错?)
请注意,在 Eric Skroch 的示例中,他从 numberOfRecordsForPlot: 返回 [plotData count],并且 plotData 在初始化时为空。
关于ios - 使用 Core-Plot 的实时图上未说明的水平线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25733724/
我正在查看预先重写的 jQuery 代码。我无法理解以下代码。 $('body > *:not(#print-modal):not(script)').clone(); 最佳答案 此选择器匹配以下任何
所以我开始学习MySQL,我对表有点困惑,所以我想澄清一下。数据库中可以有多个表吗?例如: Database1 -Table1 -Username -Password -Table2 -Name
我在 PostgreSQL 中编写了一个函数,其代码如下: for (i = 0; i str[0][i]); values[i] = datumCopy(dat_value,
oid: 行的对象标识符(对象 ID)。这个字段只有在创建表的时候使用了 WITH OIDS ,或者是设置了default_with_oids 配置参数时出现。 这个字段的类型是 oid (和字段同
我在搜索最大连接设备数时发现了 a post大致说: 当使用 P2P_STAR 时,最大设备数量为 10,因为此 topoly 使用 Wi-Fi 热点。也就是说,如果您没有路由器。 这让我问了两个问题
我不明白为什么会这样: Printf.sprintf "%08s" "s" = Printf.sprintf "%8s" "s" - : bool = true 换句话说,我希望: Printf.sp
我正在遵循 Grails in Action 中的示例。我有一个问题,如何理解 addTo*()功能有效。 我有一个简单的域:具有以下关系的用户、帖子、标签: 用户1对M发帖 用户一对一标签 发布 M
请问为什么行 "b[0]= new Child2();"在运行时而不是在编译时失败。请不要检查语法,我只是在这里做了 class Base {} class Child1 : Base {} clas
所以我想进一步加深我对套接字的理解,但是我想首先从最低级别开始(在C语言中,而不是在汇编中大声笑) 但是,我处理的大多数站点都使用SOCK_STREAM或SOCK_DGRAM。但是我已经阅读了Beej
好吧,我对 javascript 语法了解甚少,而且我对 null 的行为感到非常困惑。关于空值有很多讨论,但我似乎无法找出问题所在!请帮我。这是脚本。 var jsonData = '';
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭5 年前。 Improve thi
问题: SeriesSum 类旨在计算以下系列的总和: 类名:SeriesSum 数据成员/实例变量: x:存储整数 n:存储术语数量 sum:用于存储系列总和的双变量 成员函数: SeriesSum
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
今天我在 logcat 中注意到以下内容: D/OpenGLRenderer:0xa2c70600 (CardView) 上的 endAllStagingAnimators,句柄为 0xa2c9d35
如何创建值有序对的列表,例如list1 [(x, y), (x1, y1) ...].?? 学习如何创建此列表后,我需要知道如何将 x 值提供给列表中的用户输入并搜索 x 的下一个值并显示有序对 (x
我在存储过程中有以下逻辑。 这里完成了什么? 如果color为null,替换为'' IF ISNULL(@color, '') <> '' BEGIN END 最佳答案 它等同于: IF (@colo
我知道.Net中的接口(interface)定义了接口(interface)和继承它的类之间的契约。刚刚完成了一个大量使用数据访问层接口(interface)的项目,这让我开始思考。 . .有什么大不
如何防止基类方法被子类覆盖 最佳答案 您不需要做任何特别的事情:默认情况下方法是不可覆盖的。相反,如果您希望该方法可重写,则必须将 virtual 关键字添加到其声明中。 但是请注意,即使方法不可重写
我已阅读以下有关工厂模式的文章 here 请仅引用Class Registration - avoiding reflection这一部分。 这个版本在没有反射的情况下实现了工厂和具体产品之间的减少耦
我正在学习 Java 类(class),但无法完全理解下一课的内容。 目的:本课的目的是通过创建一个模拟 for-each 循环如何工作的替代方案来解释 for-each 循环的工作方式。 在上一课中
我是一名优秀的程序员,十分优秀!