CorePlot:如何向 CurvedScatterPlot 添加绘图点?
CorePlot: How to add a plotting point to CurvedScatterPlot?
我现在第一次使用 CorePlot 来绘制图表。我的图表显示正常。一切都画好了。我正在搜索,但找不到这个问题的答案:如何用绘图点标记图表上的最大点和最小点,以及如何显示高于或低于该点的值?我不想展示每一点的价值。我看到一些使用此功能的评论:
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
但是那个东西怎么用呢?
编辑: 我使用 CPTPlotSymbol
添加了绘图点。问题是,我只想为两个值添加 CPTPlotSymbol
。怎么做?
在准备绘图时,查找并存储 min/max 个点的索引:
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;
}
您可以在散点图上的每个点绘制不同的绘图符号。为每个数据索引实施 -symbolForScatterPlot:recordIndex:
数据源方法和 return 适当的符号。 Return [NSNull null]
如果您不想在该索引处使用符号。 Return nil
在该索引处使用地块的 plotSymbol
。
我现在第一次使用 CorePlot 来绘制图表。我的图表显示正常。一切都画好了。我正在搜索,但找不到这个问题的答案:如何用绘图点标记图表上的最大点和最小点,以及如何显示高于或低于该点的值?我不想展示每一点的价值。我看到一些使用此功能的评论:
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
但是那个东西怎么用呢?
编辑: 我使用 CPTPlotSymbol
添加了绘图点。问题是,我只想为两个值添加 CPTPlotSymbol
。怎么做?
在准备绘图时,查找并存储 min/max 个点的索引:
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;
}
您可以在散点图上的每个点绘制不同的绘图符号。为每个数据索引实施 -symbolForScatterPlot:recordIndex:
数据源方法和 return 适当的符号。 Return [NSNull null]
如果您不想在该索引处使用符号。 Return nil
在该索引处使用地块的 plotSymbol
。