核心图:在散点图中仅绘制一个点?
我有一个包含两个图的图表。一张图显示 10 个数据点并且是静态的。第二张图应仅显示一个数据点,该数据点是滑块选择的函数。
但是,每当我移动滑块来计算单个数据点的坐标时,绘图都会生成一系列点,直到我停止滑动。我想删除这一点点,只显示滑块停止位置所代表的点。希望这是有道理的。
图表如下(错误地):
哎呀,我太新了,无法发布图像,但我确信您明白了。
这是滑块 IBAction 中的部分代码:
CPTScatterPlot *dotPlot = [[[CPTScatterPlot alloc] init] autorelease];
dotPlot.identifier = @"Blue Plot";
dotPlot.dataSource = self;
dotPlot.dataLineStyle = nil;
[graph addPlot:dotPlot];
NSMutableArray *dotArray = [NSMutableArray arrayWithCapacity:1];
NSNumber *xx = [NSNumber numberWithFloat:[estMonthNumber.text floatValue]];
NSNumber *yy = [NSNumber numberWithFloat:[estMonthYield.text floatValue]];
[dotArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:xx,@"x",yy,@"y", nil]];
CPTMutableLineStyle *dotLineStyle = [CPTMutableLineStyle lineStyle];
dotLineStyle.lineColor = [CPTColor blueColor];
CPTPlotSymbol *yieldSymbol = [CPTPlotSymbol ellipsePlotSymbol];
yieldSymbol.fill = [CPTFill fillWithColor:[CPTColor blueColor]];
yieldSymbol.size = CGSizeMake(10.0, 10.0);
dotPlot.plotSymbol = yieldSymbol;
self.dataForPlot = dotArray;
我尝试使用 [dotPlot reloadData] 重新加载绘图,甚至尝试删除并添加回 dotPlot,但似乎都不起作用,或者也许我将说明放入错误的地方或错误的顺序。
任何建议将不胜感激。
I have a graph with two plots. One plot shows 10 data points and is static. The second plot should only show one data point that is a function of a slider selection.
However, whenever I move the slider to compute the coordinates of the single data point, the plot generates a whole series of points until I stop sliding. I would like to remove this trail of dots and only show the one represented by the stopping position of the slider. Hope this makes sense.
Here is what the graph looks like (erroneously):
Oops, I'm too new to post an image, but I'm sure you get the picture.
Here is a portion of the code in the slider IBAction:
CPTScatterPlot *dotPlot = [[[CPTScatterPlot alloc] init] autorelease];
dotPlot.identifier = @"Blue Plot";
dotPlot.dataSource = self;
dotPlot.dataLineStyle = nil;
[graph addPlot:dotPlot];
NSMutableArray *dotArray = [NSMutableArray arrayWithCapacity:1];
NSNumber *xx = [NSNumber numberWithFloat:[estMonthNumber.text floatValue]];
NSNumber *yy = [NSNumber numberWithFloat:[estMonthYield.text floatValue]];
[dotArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:xx,@"x",yy,@"y", nil]];
CPTMutableLineStyle *dotLineStyle = [CPTMutableLineStyle lineStyle];
dotLineStyle.lineColor = [CPTColor blueColor];
CPTPlotSymbol *yieldSymbol = [CPTPlotSymbol ellipsePlotSymbol];
yieldSymbol.fill = [CPTFill fillWithColor:[CPTColor blueColor]];
yieldSymbol.size = CGSizeMake(10.0, 10.0);
dotPlot.plotSymbol = yieldSymbol;
self.dataForPlot = dotArray;
I've tried to reload the plot with [dotPlot reloadData] and even tried to remove and add back the dotPlot but neither seems to work or, perhaps, I am putting the instructions in the wrong place or wrong sequence.
Any advice would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要在滑块操作中重新创建散点图?在该方法中您唯一需要做的就是更新为第二个图提供数据的数组,并调用 reloadData。
无论如何,您获得线索的原因是您不断创建新的绘图并将它们添加到图表中。滑块方法中唯一应该包含的代码是:
Why are you recreating the scatterplot in the slider action? The only thing you should need to do in that method is update the array that provides the data for the second plot, and call reloadData.
In any case, the reason you're getting the trail is that you keep creating new plots and adding them to the graph. The only code that should be in the slider method is:
我想我距离解决方案只有一行代码。正如通常发生的那样,我梦想着解决方案。首先,我从滑块方法中删除了所有 NSMutableArray *dotArray 等代码。其次,我按照 Flyingdiver 的建议在滑块方法中保留了 [graph reloadData]。第三,我修改了数据源方法如下:
再次感谢 Flyingdiver 提供的线索解决了我的谜团。我学到了很多。
I figured I was about a line of code away from a solution. As typically happens, I dreamt the solution. First I removed all the NSMutableArray *dotArray, etc, etc code from the slider method. Second I retained the [graph reloadData] in the slider method as Flyingdiver advised. Third, I modified the datasource methods as follows:
Once again, thanks a million to Flyingdiver for the clues that solved my mystery. I learned a lot.