Skip to content

The Axis

Philipp Jahoda edited this page Sep 28, 2015 · 15 revisions

This wiki page focuses on the AxisBase class, the baseclass of both XAxis (XAxis) and YAxis (YAxis). Introduced in v2.0.0

The following methods mentioned below can be applied to both axes.

The axis classes allow specific styling and consist (can consist) of the following components/parts:

  • The labels (drawn in vertical (y-axis) or horizontal (x-axis) alignment), which contain the axis description values
  • A so called "axis-line" that is drawn directly next to and parallel to the labels
  • The "grid-lines", each originating from an axis-label in horizontal direction
  • LimitLines, that allow to present special infomation, like borders or constraints

Control which parts (of the axis) should be drawn

  • setEnabled(boolean enabled): Sets the axis enabled or disabled. If disabled, no part of the axis will be drawn.
  • setDrawAxisLine(boolean enabled): Set this to true if the line alongside the axis (axis-line) should be drawn or not.
  • setDrawGridLines(boolean enabled): Set this to true to enable drawing the grid lines for the axis.
  • setDrawLabels(boolean enabled): Set this to true to enable drawing the labels of the axis.

Styling / modifying the axis

  • setTextColor(int color): Sets the color of the axis labels.
  • setTextSize(float size): Sets the text-size of the axis labels in dp.
  • setTypeface(Typeface tf): Sets a custom Typeface for the axis labels.
  • setGridColor(int color): Sets the color of the grid-lines of this axis.
  • setGridLineWidth(float width): Sets the width of the grid-lines of this axis.
  • setAxisLineColor(int color): Sets the color of the axis-line of this axis.
  • setAxisLineWidth(float width): Sets the width of the axis-line of this axis.
  • enableGridDashedLine(float lineLength, float spaceLength, float phase): Enables the grid line to be drawn in dashed mode, e.g. like this "- - - - - -". "lineLength" controls the length of the line pieces, "spaceLength" controls the space between the lines, "phase" controls the starting point.

Limit Lines

Both axes support so called LimitLines that allow to present special information, like borders or constraints. LimitLines added to the YAxis are drawn in horizontal direction, and in vertical direction when added to the XAxis. This is how you add and remove LimitLines from the axis:

  • addLimitLine(LimitLine l): Adds a new LimitLine to this axis.
  • removeLimitLine(LimitLine l): Removes the specified LimitLine from this axis.
  • More methods for adding / removing available as well.
  • setDrawLimitLinesBehindData(boolean enabled): Allows to control the z-order between the LimitLines and the actual data. If this is set to true, the LimitLines are drawn behind the actual data, otherwise on top. Default: false

Limit lines (class LimitLine) are (as the name might indicate) plain and simple lines can be used to provide additional information for the user.

As an example, your chart might display various blood pressure measurement results the user logged with an application. In order to inform the user that a systolic blood pressure of over 140 mmHg is considered to be a health risk, you could add a LimitLine at 140 to provide that information.

Example Code

YAxis leftAxis = chart.getAxisLeft();

LimitLine ll = new LimitLine(140f, "Critical Blood Pressure");
ll.setLineColor(Color.RED);
ll.setLineWidth(4f);
ll.setTextColor(Color.BLACK);
ll.setTextSize(12f);
// .. and more styling options

leftAxis.addLimitLine(ll);

The documentation has moved.

Clone this wiki locally