Reputation: 1107
I am using CorePlot for the first time now for graphs. My graph is showing ok. Everything is drawn ok. I was searching but I could not find answer to this question: how to mark maximum and minimum point on my graph with a plotting point and how to show that value above or below that point? I do not want to show value of every point. I've seen some comments to use this:
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index
but how to use that thing?
EDIT: I've added plotting points using CPTPlotSymbol
. The problem is, I want to add CPTPlotSymbol
only for two values. How to do that?
Upvotes: 0
Views: 97
Reputation: 27381
You can plot different plot symbols at each point on a scatter plot. Implement the -symbolForScatterPlot:recordIndex:
datasource method and return the appropriate symbol for each data index. Return [NSNull null]
if you don't want a symbol at that index. Return nil
to use the plot's plotSymbol
at that index.
Upvotes: 1
Reputation: 1288
In preparing your plot, find and store indices of min/max points:
NSUInteger indexOfMin = ...
NSUInteger indexOfMax = ...
Then in -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;
}
Upvotes: 2