How to put y axis number in Core Plot?
I would like my Scatter graph I am making with Core Plot library to show Y value near every point relative to X data.
I looked at CPTTestApp project from Core Plot examples, but I simply don't get it. First I thought the secret lies in
-(CPTPlotSymbol *)symbolForScatterPlot:(CPTScatterPlot *)plot recordIndex:(NSUInteger)index
method and I have implemented it in my project. Yes, I got points drawn, which is nice, but I found out this probably has nothing to do with values being shown near points....
This suspicion was confirmed when I opened Candlestick demo from Plot_Galley_Mac demo. There is no method from above and it shows numbers nicely!
If anyone can, please, help me. Otherwise, I would like to thank developers for sharing this library with us. Beside over usage of NSDecimal structure and a bit thin manual and reference data, this is fabulous project.
You're looking for "data labels". CPTPlot has a number of properties that control the built-in labeling functions:
- labelOffset: distance between the point and the label
- labelRotation: rotation angle
- labelTextStyle: text style used to draw the labels
- labelFormatter: number (or date) formatter used to format the labels
- labelShadow: shadow properties applied to the labels
If the built-in labels don't meet your needs, you can create your own. Implement the -dataLabelForPlot:recordIndex: datasource method and return the desired label for each point. Custom labels can be any CPTLayer so you can make anything you want—text, images, or any custom layer that you create.