Core Plot (iOS and tvOS)
Cocoa plotting framework for macOS, iOS, and tvOS
CPTGraph Class Reference

An abstract graph class. More...

#import <CPTGraph.h>

+ Inheritance diagram for CPTGraph:
+ Collaboration diagram for CPTGraph:

Public Instance Methods

Data Source
(void) - reloadData
 Makes all plots reload their data. More...
 
(void) - reloadDataIfNeeded
 Makes all plots reload their data if their data cache is out of date. More...
 
Retrieving Plots
(nonnull CPTPlotArray *) - allPlots
 All plots associated with the graph. More...
 
(nullable CPTPlot *) - plotAtIndex:
 Gets the plot at the given index in the plot array. More...
 
(nullable CPTPlot *) - plotWithIdentifier:
 Gets the plot with the given identifier from the plot array. More...
 
Adding and Removing Plots
(void) - addPlot:
 Add a plot to the default plot space. More...
 
(void) - addPlot:toPlotSpace:
 Add a plot to the given plot space. More...
 
(void) - removePlot:
 Remove a plot from the graph. More...
 
(void) - removePlotWithIdentifier:
 Remove a plot from the graph. More...
 
(void) - insertPlot:atIndex:
 Add a plot to the default plot space at the given index in the plot array. More...
 
(void) - insertPlot:atIndex:intoPlotSpace:
 Add a plot to the given plot space at the given index in the plot array. More...
 
Retrieving Plot Spaces
(nonnull CPTPlotSpaceArray *) - allPlotSpaces
 All plot spaces associated with the graph. More...
 
(nullable CPTPlotSpace *) - plotSpaceAtIndex:
 Gets the plot space at the given index in the plot space array. More...
 
(nullable CPTPlotSpace *) - plotSpaceWithIdentifier:
 Gets the plot space with the given identifier from the plot space array. More...
 
Adding and Removing Plot Spaces
(void) - addPlotSpace:
 Add a plot space to the graph. More...
 
(void) - removePlotSpace:
 Remove a plot space from the graph. More...
 
Themes
(void) - applyTheme:
 Apply a theme to style the graph. More...
 
Initialization
(nonnull instancetype) - initWithFrame: [implementation]
 Initializes a newly allocated CPTGraph object with the provided frame rectangle. More...
 
User Interaction
(BOOL- pointingDeviceDownEvent:atPoint: [implementation]
 Informs the receiver that the user has touched the screen. More...
 
(BOOL- pointingDeviceUpEvent:atPoint: [implementation]
 Informs the receiver that the user has lifted their finger off the screen. More...
 
(BOOL- pointingDeviceDraggedEvent:atPoint: [implementation]
 Informs the receiver that the user has moved their finger while touching the screen. More...
 
(BOOL- pointingDeviceCancelledEvent: [implementation]
 Informs the receiver that tracking of touches has been cancelled for any reason. More...
 
Factory Methods
(nullable CPTPlotSpace *) - newPlotSpace
 Creates a new plot space for the graph. More...
 
(nullable CPTAxisSet *) - newAxisSet
 Creates a new axis set for the graph. More...
 
- Public Instance Methods inherited from CPTBorderedLayer
(void) - renderBorderedLayerAsVectorInContext:
 Draws the fill and border of a CPTBorderedLayer into the given graphics context. More...
 
(void) - sublayerMarginLeft:top:right:bottom: [implementation]
 Increases the sublayer margin on all four sides by half the width of the border line style. More...
 
- Public Instance Methods inherited from CPTAnnotationHostLayer
(void) - addAnnotation:
 Adds an annotation to the receiver. More...
 
(void) - removeAnnotation:
 Removes an annotation from the receiver. More...
 
(void) - removeAllAnnotations
 Removes all annotations from the receiver. More...
 
- Public Instance Methods inherited from CPTLayer
(nullable instancetype) - initWithCoder:
 Returns an object initialized from data in a given unarchiver. More...
 
(nonnull instancetype) - initWithLayer:
 Override to copy or initialize custom fields of the specified layer. More...
 
(nonnull instancetype) - init [implementation]
 Initializes a newly allocated CPTLayer object with an empty frame rectangle. More...
 
(void) - logLayers
 Logs this layer and all of its sublayers. More...
 
(BOOL- pointingDeviceDownEvent:atPoint: [implementation]
 
(BOOL- pointingDeviceUpEvent:atPoint: [implementation]
 
(BOOL- pointingDeviceDraggedEvent:atPoint: [implementation]
 
(BOOL- pointingDeviceCancelledEvent: [implementation]
 
(nullable CPTNativeImage *) - imageOfLayer
 Gets an image of the layer contents. More...
 
(void) - setNeedsDisplayAllLayers
 Recursively marks this layer and all sublayers as needing to be redrawn. More...
 
(void) - renderAsVectorInContext:
 Draws layer content into the provided graphics context. More...
 
(void) - recursivelyRenderInContext:
 Draws layer content and the content of all sublayers into the provided graphics context. More...
 
(void) - layoutAndRenderInContext:
 Updates the layer layout if needed and then draws layer content and the content of all sublayers into the provided graphics context. More...
 
(nonnull NSData *) - dataForPDFRepresentationOfLayer
 Draws layer content and the content of all sublayers into a PDF document. More...
 
(void) - applySublayerMaskToContext:forSublayer:withOffset:
 Recursively sets the clipping path of the given graphics context to the sublayer masking paths of its superlayers. More...
 
(void) - applyMaskToContext:
 Sets the clipping path of the given graphics context to mask the content. More...
 
(void) - pixelAlign
 Align the receiver’s position with pixel boundaries. More...
 
(void) - layoutSublayers [implementation]
 Updates the layout of all sublayers. Sublayers fill the super layer’s bounds minus any padding. More...
 
- Public Instance Methods inherited from CALayer
(BOOL- containsPoint:
 
(void) - drawInContext:
 
(id- init
 
(id- initWithLayer
 
(void) - layoutSublayers
 
(void) - setNeedsDisplay
 
(void) - setNeedsDisplayInRect:
 
(void) - setNeedsLayout
 
- Public Instance Methods inherited from NSObject
(Class- classForCoder
 
(id- copy
 
(void) - dealloc
 
(void) - finalize
 
(id- init
 
(id- mutableCopy
 
- Public Instance Methods inherited from <NSObject>
(NSString *) - description
 
(NSUInteger- hash
 
(BOOL- isEqual:
 
User Interaction

Properties

Hosting View
CPTGraphHostingViewhostingView
 The hosting view that contains the graph. More...
 
Title
NSStringtitle
 The title string. More...
 
NSAttributedStringattributedTitle
 The styled title string. More...
 
CPTTextStyletitleTextStyle
 The text style of the title. More...
 
CGPoint titleDisplacement
 A vector giving the displacement of the title from the edge location. More...
 
CPTRectAnchor titlePlotAreaFrameAnchor
 The location of the title with respect to the plot area frame. Default is CPTRectAnchorTop. More...
 
Layers
CPTAxisSetaxisSet
 The axis set. More...
 
CPTPlotAreaFrameplotAreaFrame
 The plot area frame. More...
 
CPTPlotSpacedefaultPlotSpace
 The default plot space. More...
 
CPTNumberArraytopDownLayerOrder
 An array of graph layers to be drawn in an order other than the default. More...
 
Legend
CPTLegendlegend
 The graph legend. Setting this property will automatically anchor the legend to the graph and position it using the legendAnchor and legendDisplacement properties. This is a convenience property only—the legend may be inserted in the layer tree and positioned like any other CPTLayer if more flexibility is needed. More...
 
CPTRectAnchor legendAnchor
 The location of the legend with respect to the graph frame. Default is CPTRectAnchorBottom. More...
 
CGPoint legendDisplacement
 A vector giving the displacement of the legend from the edge location. More...
 
- Properties inherited from CPTBorderedLayer
CPTLineStyleborderLineStyle
 The line style for the layer border. More...
 
CPTFillfill
 The fill for the layer background. More...
 
BOOL inLayout
 Set to YES when changing the layout of this layer. Otherwise, if masking the border, all layout property changes will be passed to the superlayer. More...
 
- Properties inherited from CPTAnnotationHostLayer
CPTAnnotationArrayannotations
 An array of annotations attached to this layer. More...
 
- Properties inherited from CPTLayer
CPTGraphgraph
 The graph for the layer. More...
 
CGFloat paddingLeft
 Amount to inset the left side of each sublayer. More...
 
CGFloat paddingTop
 Amount to inset the top of each sublayer. More...
 
CGFloat paddingRight
 Amount to inset the right side of each sublayer. More...
 
CGFloat paddingBottom
 Amount to inset the bottom of each sublayer. More...
 
id< NSCopying, NSCoding, NSObjectidentifier
 An object used to identify the layer in collections. More...
 
CGFloat contentsScale
 The scale factor applied to the layer. More...
 
BOOL useFastRendering
 If YES, subclasses should optimize their drawing for speed over precision. More...
 
CPTShadowshadow
 The shadow drawn under the layer content. If nil (the default), no shadow is drawn. More...
 
CGSize shadowMargin
 The maximum margin size needed to fully enclose the layer shadow. More...
 
BOOL masksToBorder
 If YES, a sublayer mask is applied to clip sublayer content to the inside of the border. More...
 
CGPathRef outerBorderPath
 A drawing path that encompasses the outer boundary of the layer border. More...
 
CGPathRef innerBorderPath
 A drawing path that encompasses the inner boundary of the layer border. More...
 
CGPathRef maskingPath
 A drawing path that encompasses the layer content including any borders. Set to NULL when no masking is desired. More...
 
CGPathRef sublayerMaskingPath
 A drawing path that encompasses the layer content excluding any borders. Set to NULL when no masking is desired. More...
 
CPTSublayerSetsublayersExcludedFromAutomaticLayout
 A set of sublayers that should be excluded from the automatic sublayer layout. More...
 
- Properties inherited from CALayer
CGPoint anchorPoint
 
CGRect bounds
 
CGFloat contentsScale
 
CGFloat cornerRadius
 
id delegate
 
CGRect frame
 
BOOL masksToBounds
 
BOOL needsDisplayOnBoundsChange
 
BOOL opacity
 
BOOL opaque
 
- Properties inherited from <CAMediaTiming>
BOOL autoreverses
 
CFTimeInterval beginTime
 
CFTimeInterval duration
 
NSStringfillMode
 
float repeatCount
 
id repeatDuration
 
float speed
 
CFTimeInterval timeOffset
 

Additional Inherited Members

- Public Class Methods inherited from CALayer
(id+ layer
 
- Public Class Methods inherited from NSObject
(id+ alloc
 
(Class+ class
 
(void) + initialize
 
(void) + load
 
(id+ new
 
- Public Class Methods inherited from <NSSecureCoding>
(BOOL+ supportsSecureCoding:
 

Detailed Description

An abstract graph class.

The graph is the top-level view container for a Core Plot graph. It should be hosted inside a CPTGraphHostingView.

A graph contains a single plot area frame (CPTPlotAreaFrame), which is the container for all of the graph elements. Use the padding properties on the graph to position the plot area frame inside the graph. All graph elements, except for titles, legends, and other annotations attached directly to the graph itself are clipped to the plot area frame.

The plot area (CPTPlotArea) sits inside the plot area frame. Use the padding properties on the plot area frame to position the plot area inside the plot area frame. All plots are drawn inside this area while axes, titles, and borders may fall outside. Use a plot space (CPTPlotSpace) to control the mapping between data values and plotting coordinates in the plot area. One plot space is automatically provided with a new graph; more may be added as needed.

See also
See Graphs for a list of animatable properties.

Method Documentation

◆ addPlot:

- (void) addPlot: (nonnull CPTPlot *)  plot

Add a plot to the default plot space.

Parameters
plotThe plot.

◆ addPlot:toPlotSpace:

- (void) addPlot: (nonnull CPTPlot *)  plot
toPlotSpace: (nullable CPTPlotSpace *)  space 

Add a plot to the given plot space.

Parameters
plotThe plot.
spaceThe plot space.

◆ addPlotSpace:

- (void) addPlotSpace: (nonnull CPTPlotSpace *)  space

Add a plot space to the graph.

Parameters
spaceThe plot space.

◆ allPlots

- (nonnull CPTPlotArray *) allPlots

All plots associated with the graph.

Returns
An array of all plots associated with the graph.

◆ allPlotSpaces

- (nonnull CPTPlotSpaceArray *) allPlotSpaces

All plot spaces associated with the graph.

Returns
An array of all plot spaces associated with the graph.

◆ applyTheme:

- (void) applyTheme: (nullable CPTTheme *)  theme

Apply a theme to style the graph.

Parameters
themeThe theme object used to style the graph.

◆ initWithFrame:

- (nonnull instancetype) initWithFrame: (CGRect newFrame
implementation

Initializes a newly allocated CPTGraph object with the provided frame rectangle.

This is the designated initializer. The initialized layer will have the following properties:

The new graph will have a plotAreaFrame with a frame equal to the graph’s bounds, a defaultPlotSpace created with the -newPlotSpace method, and an axisSet created with the -newAxisSet method.

Parameters
newFrameThe frame rectangle.
Returns
The initialized CPTGraph object.

Reimplemented from CPTBorderedLayer.

Reimplemented in CPTXYGraph.

◆ insertPlot:atIndex:

- (void) insertPlot: (nonnull CPTPlot *)  plot
atIndex: (NSUInteger idx 

Add a plot to the default plot space at the given index in the plot array.

Parameters
plotThe plot.
idxAn index within the bounds of the plot array.

◆ insertPlot:atIndex:intoPlotSpace:

- (void) insertPlot: (nonnull CPTPlot *)  plot
atIndex: (NSUInteger idx
intoPlotSpace: (nullable CPTPlotSpace *)  space 

Add a plot to the given plot space at the given index in the plot array.

Parameters
plotThe plot.
idxAn index within the bounds of the plot array.
spaceThe plot space.

◆ newAxisSet

- (nullable CPTAxisSet *) newAxisSet

Creates a new axis set for the graph.

Returns
A new axis set.

Provided by category CPTGraph(AbstractFactoryMethods).

◆ newPlotSpace

- (nullable CPTPlotSpace *) newPlotSpace

Creates a new plot space for the graph.

Returns
A new plot space.

Provided by category CPTGraph(AbstractFactoryMethods).

◆ plotAtIndex:

- (nullable CPTPlot *) plotAtIndex: (NSUInteger idx

Gets the plot at the given index in the plot array.

Parameters
idxAn index within the bounds of the plot array.
Returns
The plot at the given index.

◆ plotSpaceAtIndex:

- (nullable CPTPlotSpace *) plotSpaceAtIndex: (NSUInteger idx

Gets the plot space at the given index in the plot space array.

Parameters
idxAn index within the bounds of the plot space array.
Returns
The plot space at the given index.

◆ plotSpaceWithIdentifier:

- (nullable CPTPlotSpace *) plotSpaceWithIdentifier: (nullable id<NSCopying>)  identifier

Gets the plot space with the given identifier from the plot space array.

Parameters
identifierA plot space identifier.
Returns
The plot space with the given identifier or nil if it was not found.

◆ plotWithIdentifier:

- (nullable CPTPlot *) plotWithIdentifier: (nullable id<NSCopying>)  identifier

Gets the plot with the given identifier from the plot array.

Parameters
identifierA plot identifier.
Returns
The plot with the given identifier or nil if it was not found.

◆ pointingDeviceCancelledEvent:

- (BOOL) pointingDeviceCancelledEvent: (nonnull CPTNativeEvent *)  event
implementation

Informs the receiver that tracking of touches has been cancelled for any reason.

The event is passed in turn to the following layers:

  1. All plots in reverse order (i.e., from front to back in the layer order)
  2. The axis set
  3. The plot area
  4. The legend

If any layer handles the event, subsequent layers are not notified and this method immediately returns YES. If none of the layers handle the event, it is passed to all plot spaces whether they handle it or not.

Parameters
eventThe OS event.
Returns
Whether the event was handled or not.

Reimplemented from CPTAnnotationHostLayer.

◆ pointingDeviceDownEvent:atPoint:

- (BOOL) pointingDeviceDownEvent: (nonnull CPTNativeEvent *)  event
atPoint: (CGPoint interactionPoint 
implementation

Informs the receiver that the user has touched the screen.

The event is passed in turn to the following layers:

  1. All plots in reverse order (i.e., from front to back in the layer order)
  2. The axis set
  3. The plot area
  4. The legend

If any layer handles the event, subsequent layers are not notified and this method immediately returns YES. If none of the layers handle the event, it is passed to all plot spaces whether they handle it or not.

Parameters
eventThe OS event.
interactionPointThe coordinates of the interaction.
Returns
Whether the event was handled or not.

Reimplemented from CPTAnnotationHostLayer.

◆ pointingDeviceDraggedEvent:atPoint:

- (BOOL) pointingDeviceDraggedEvent: (nonnull CPTNativeEvent *)  event
atPoint: (CGPoint interactionPoint 
implementation

Informs the receiver that the user has moved their finger while touching the screen.

The event is passed in turn to the following layers:

  1. All plots in reverse order (i.e., from front to back in the layer order)
  2. The axis set
  3. The plot area
  4. The legend

If any layer handles the event, subsequent layers are not notified and this method immediately returns YES. If none of the layers handle the event, it is passed to all plot spaces whether they handle it or not.

Parameters
eventThe OS event.
interactionPointThe coordinates of the interaction.
Returns
Whether the event was handled or not.

Reimplemented from CPTAnnotationHostLayer.

◆ pointingDeviceUpEvent:atPoint:

- (BOOL) pointingDeviceUpEvent: (nonnull CPTNativeEvent *)  event
atPoint: (CGPoint interactionPoint 
implementation

Informs the receiver that the user has lifted their finger off the screen.

The event is passed in turn to the following layers:

  1. All plots in reverse order (i.e., from front to back in the layer order)
  2. The axis set
  3. The plot area
  4. The legend

If any layer handles the event, subsequent layers are not notified and this method immediately returns YES. If none of the layers handle the event, it is passed to all plot spaces whether they handle it or not.

Parameters
eventThe OS event.
interactionPointThe coordinates of the interaction.
Returns
Whether the event was handled or not.

Reimplemented from CPTAnnotationHostLayer.

◆ reloadData

- (void) reloadData

Makes all plots reload their data.

◆ reloadDataIfNeeded

- (void) reloadDataIfNeeded

Makes all plots reload their data if their data cache is out of date.

◆ removePlot:

- (void) removePlot: (nullable CPTPlot *)  plot

Remove a plot from the graph.

Parameters
plotThe plot to remove.

◆ removePlotSpace:

- (void) removePlotSpace: (nullable CPTPlotSpace *)  plotSpace

Remove a plot space from the graph.

Parameters
plotSpaceThe plot space.

◆ removePlotWithIdentifier:

- (void) removePlotWithIdentifier: (nullable id<NSCopying>)  identifier

Remove a plot from the graph.

Parameters
identifierThe identifier of the plot to remove.

Property Documentation

◆ attributedTitle

- (nullable NSAttributedString *) attributedTitle
readwritenonatomiccopy

The styled title string.

Assigning a new value to this property also sets the value of the title property to the same string without formatting information. It also replaces the titleTextStyle with a style matching the first position (location 0) of the styled title. Default is nil.

◆ axisSet

- (nullable CPTAxisSet *) axisSet
readwritenonatomicstrong

The axis set.

◆ defaultPlotSpace

- (nullable CPTPlotSpace *) defaultPlotSpace
readnonatomicassign

The default plot space.

◆ hostingView

- (nullable CPTGraphHostingView *) hostingView
readwritenonatomicweak

The hosting view that contains the graph.

◆ legend

- (nullable CPTLegend *) legend
readwritenonatomicstrong

The graph legend. Setting this property will automatically anchor the legend to the graph and position it using the legendAnchor and legendDisplacement properties. This is a convenience property only—the legend may be inserted in the layer tree and positioned like any other CPTLayer if more flexibility is needed.

◆ legendAnchor

- (CPTRectAnchor) legendAnchor
readwritenonatomicassign

The location of the legend with respect to the graph frame. Default is CPTRectAnchorBottom.

◆ plotAreaFrame

- (nullable CPTPlotAreaFrame *) plotAreaFrame
readwritenonatomicstrong

The plot area frame.

◆ title

- (nullable NSString *) title
readwritenonatomiccopy

The title string.

Assigning a new value to this property also sets the value of the attributedTitle property to nil.

◆ titlePlotAreaFrameAnchor

- (CPTRectAnchor) titlePlotAreaFrameAnchor
readwritenonatomicassign

The location of the title with respect to the plot area frame. Default is CPTRectAnchorTop.

◆ titleTextStyle

- (nullable CPTTextStyle *) titleTextStyle
readwritenonatomiccopy

The text style of the title.

Assigning a new value to this property also sets the value of the attributedTitle property to nil.

◆ topDownLayerOrder

- (nullable CPTNumberArray *) topDownLayerOrder
readwritenonatomicstrong

An array of graph layers to be drawn in an order other than the default.

See also
CPTPlotArea topDownLayerOrder property.

The documentation for this class was generated from the following files: