-
Notifications
You must be signed in to change notification settings - Fork 382
Data Source
PRE-RELEASE DOCUMENTATION
The master branch of the project doesn't use forBEMSimpleLineGraphDataSource
currently. This feature is supported on the feature branch. Please make sure to read the feature branch warning before working with it. On the master branch, all of the referenced methods are available onBEMSimpleLineGraphDelegate
.
###Number of Points on the Graph
Implement this method to specify the number of points on your graph. BEMSimpleLineGraph will pass the graph of interest in the graph
parameter. You will need to return an NSInteger
which represents the number of points in the line graph. The line graph gets the value returned by this method from its data source and caches it.
- (NSInteger)numberOfPointsInLineGraph:(BEMSimpleLineGraphView *)graph {
return X; // Number of points in the graph.
}
###Graph Values and Points
Informs the position of each point on the Y-Axis at a given index. This method is called for every point specified in the numberOfPointsInLineGraph:
method. The parameter index
is the position from left to right of the point on the X-Axis:
- (CGFloat)lineGraph:(BEMSimpleLineGraphView *)graph valueForPointAtIndex:(NSInteger)index {
return …; // The value of the point on the Y-Axis for the index.
}
##Reloading Data Similar to a UITableView's `reloadData` method, BEMSimpleLineGraph has a `reloadGraph` method. Call this method to reload all the data that is used to construct the graph, including points, axis, index arrays, colors, alphas, and so on. Calling this method will cause the line graph to call `layoutSubviews` on itself. The line graph will also call all of its data source and delegate methods again (to get the updated data).
- (void)anyMethodInYourOwnController {
// Change graph properties
// Update data source / arrays
// Reload the graph
[self.myGraph reloadGraph];
}
##Retrieving Data The values submitted through the data source delegate methods are saved / recorded. You can retrieve the line graph's current data points and X-Axis with the two methods below.
// Retrieve current X-Axis values
NSArray *arrayOfXLabels = [self.myGraph graphValuesForXAxis]; // The returned NSArray contains an array of NSString objects
// Retrieve the Data Points
NSArray *arrayOfDataPoints = [self.myGraph graphValuesForDataPoints]; // The returned NSArray contains an array of NSNumber objects (originally formatted as a float).