简体   繁体   中英

CorePlot: How to add a plotting point to CurvedScatterPlot?

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?

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;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM