Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Touch Reporting (Interactive Graph)

Samuel Spencer edited this page Aug 3, 2017 · 2 revisions

BEMSimpleLineGraph can react to the user touching the graph by two different ways:

  • Popup Reporting
  • Touch Reporting

On the above example, both Popup Reporting and Touch Reporting are activated.


Popup Reporting

When the user touches and drags his finger along the graph, a popup label will appear on top of the closest dot from the user's finger. The label will display the value of the point.
To enable Popup Reporting, simply set the BOOL property enablePopUpReport to YES.

self.myGraph.enablePopUpReport = YES;

If the property alwaysDisplayPopUpLabels is set to YES, all of the popup up labels will always be visible (defaults to NO).


Touch Reporting

When the user touches and drags his finger along the graph, it's possible to retrive the value of the closest point.
To do so, first toggle the enableTouchReport property:

self.myGraph.enableTouchReport = YES;

Next, implement the two following methods: lineGraph:didTouchGraphWithClosestIndex & lineGraph:didReleaseTouchFromGraphWithClosestIndex:.

  1. The lineGraph:didTouchGraphWithClosestIndex method gets called when the user touches the graph. The parameter index is the closest index (X-Axis) from the user's finger position.
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didTouchGraphWithClosestIndex:(NSInteger)index {
// Here you could change the text of a UILabel with the value of the closest index for example.
}
  1. The lineGraph:didReleaseTouchFromGraphWithClosestIndex: method gets called when the user stops touching the graph. The parameter index is the closest index (X-Axis) from the user's last finger position.
- (void)lineGraph:(BEMSimpleLineGraphView *)graph didReleaseTouchFromGraphWithClosestIndex:(CGFloat)index {
// Set the UIlabel alpha to 0 for example.
}