This repository has been archived by the owner on Dec 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 382
Axis Labels
Boris-Em edited this page Jun 30, 2014
·
19 revisions
BEMSimpleLineGraph offers easy ways to include labels along the graph's axis.
#X-Axis To add labels along the X-Axis, simply implement the following method: `lineGraph:labelOnXAxisForIndex:`. The text to be displayed for each UILabel on the X-Axis at a given index. It should return as many strings as the number of points on the graph. ```Objective-C - (NSString *)lineGraph:(BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index { return …; } ``` ###Gaps between labels When only implementing `lineGraph:labelOnXAxisForIndex:`, the labels might overlap. Thankfully, BEMSimpleLineGraph offers different way to prevent this: * Using a modulo operation Click [here](http://en.wikipedia.org/wiki/Modulo_operation) to learn more about modulo operations. This is probably the easiest way to skip some labels in order to avoid overlaps. In the following example, only every other label will be displayed: ```Objective-C - (NSString *)lineGraph:(BEMSimpleLineGraphView *)graph labelOnXAxisForIndex:(NSInteger)index { if ((index % 2) == 1) return [self.ArrayOfDates objectAtIndex:index]; else return @""; } ```-
Using the method
numberOfGapsBetweenLabelsOnLineGraph:
numberOfGapsBetweenLabelsOnLineGraph:
informs how much empty space is needed between each displayed label. Returning 0 will display all of the labels (just like if this method wasn't implemented). Returning the total number of labels will only display the first and last label. See the image below for clarification.
- (NSInteger)numberOfGapsBetweenLabelsOnLineGraph:(BEMSimpleLineGraphView *)graph {
return X; // The number of hidden labels between each displayed label.
}
On the left, numberOfGapsBetweenLabelsOnLineGraph: returns 0, in the middle it returns 1 and on the right it returns the number of points in the graph.
-
Using the property
removeOverlappingLabelsOnAxis
If this property is set to YES, the overlapping labels on the axis will automatically be removed. It can be used as a "safety net" in combination of one of the previous way to skip labels.
Its default value is NO.
self.myGraph.removeOverlappingLabelsOnAxis = YES;
###X-Axis Label Color
The property colorXaxisLabel
controls the color of the text of the UILabels on the X-Axis:
@property (strong, nonatomic) UIColor *colorXaxisLabel;