【问题标题】:CorePlot: How to add a plotting point to CurvedScatterPlot?CorePlot:如何向 CurvedScatterPlot 添加绘图点?
【发布时间】:2015-12-17 16:05:02
【问题描述】:
我现在第一次使用 CorePlot 来绘制图表。我的图表显示正常。一切都画好了。我正在搜索,但找不到这个问题的答案:如何用绘图点在图表上标记最大值和最小值,以及如何在该点上方或下方显示该值?我不想显示每一点的价值。我见过一些 cmets 使用这个:
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
但是那东西怎么用呢?
编辑:我使用CPTPlotSymbol 添加了绘图点。问题是,我只想为两个值添加CPTPlotSymbol。该怎么做?
【问题讨论】:
标签:
ios
objective-c
core-plot
【解决方案1】:
在准备绘图时,查找并存储最小/最大点的索引:
NSUInteger indexOfMin = ...
NSUInteger indexOfMax = ...
然后在-dataLabelForPlot:recordIndex::
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
if (plot.identifier == yourPlotID) // optional if you only have one plot
{
if (index == indexOfMin)
{
return [[CPTTextLayer alloc] initWithText:@"Your Min Label"];
}
else if (index == indexOfMax)
{
return [[CPTTextLayer alloc] initWithText:@"Your Max Label"];
}
}
return nil;
}
【解决方案2】:
您可以在散点图上的每个点绘制不同的绘图符号。实现-symbolForScatterPlot:recordIndex: 数据源方法并为每个数据索引返回适当的符号。如果您不想要该索引处的符号,请返回 [NSNull null]。返回 nil 以在该索引处使用绘图的 plotSymbol。