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

Average Lines

Sam Spencer edited this page Apr 7, 2015 · 1 revision

Graphs with BEMSimpleLineGraph are drawn with a single line and have an optional average line available for drawing.

The average line can be set to any y-value and drawn in a straight, horizontal line across the graph.

Enabling an Average Line

The averageLine property is a BEMAverageLine which allows you to enable and customize the average line. Set its enableAverageLine property to YES to display the line.

self.myGraph.averageLine.enableAverageLine = YES;

You do not need to initialize the averageLine object. BEMSimpleLineGraph will initialize it for you.

Y-Value

You may optionally set a y-value for your average line. If you do not set a y-value, the average (mean) of your points will be calculated (using the calculateAveragePointValue method) and used. Otherwise, you may specify your own y-value which could be any number on the graph (e.g. sum, median, mode, max, min, etc.).

Set the y-value of the average line by passing a float relative to the scale of your graph. For example, if your graph's y-values range between 25 and 100 pass a y-value within that range. BEMSimpleLineGraph will not validate your y-value, so it is imperative that you ensure it will be within viewing range.

self.myGraph.averageLine.yValue = [self.myGraph calculateAveragePointValue].floatValue;

Properties

There are four additional properties that can be set on the average line. These properties provide similar functionality to the properties of reference lines and the main line.

color Specify the color of the average line. Defaults to white.

width Specify the width of the average line. Defaults to 3.0f.

alpha Specify the opacity of the average line. Defaults to 1.0f.

dashPattern Specify an NSArray dash pattern for the average line. Defaults to nil.