Skip to content
Philipp Jahoda edited this page Apr 3, 2016 · 4 revisions

The XAxis is a subclass of AxisBase.

The XAxis class (in versions prior to 2.0.0 XLabels called), is the data and information container for everything related to the the horizontal axis. Each Line-, Bar-, Scatter-, CandleStick- and RadarChart has an XAxis object. The XAxis displays what is handed over to the ChartData object as an ArrayList<String> or String[] ("xVals").

The XAxis class allows specific styling and consists (can consist) of the following components/parts:

  • The labels (drawn in horizontal alignment), which contain the axis description values, these are provided by the data object you set for the chart (the x-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 vertical direction

In order to acquire an instance of the XAxis class, do the following:

XAxis xAxis = chart.getXAxis();

Customizing the axis values

  • setLabelsToSkip(int count): Sets the number of labels that should be skipped on the axis before the next label is drawn. This will disable the feature that automatically calculates an adequate space between the axis labels and set the number of labels to be skipped to the fixed number provided by this method. Call resetLabelsToSkip(...) to re-enable automatic calculation.
  • resetLabelsToSkip(): Calling this will disable a custom number of labels to be skipped (set by setLabelsToSkip(...)) while drawing the x-axis. Instead, the number of values to skip will again be calculated automatically.
  • setAvoidFirstLastClipping(boolean enabled): If set to true, the chart will avoid that the first and last axis label entry in the x-axis "clip" off the edge of the chart or the screen.
  • setSpaceBetweenLabels(int characters): Sets the space that should be left out between the x-axis labels in characters, default: 4.
  • setPosition(XAxisPosition pos): Sets the position where the XAxis should appear. Choose between TOP, BOTTOM, BOTH_SIDED, TOP_INSIDE or BOTTOM_INSIDE.

Formatting values

  • setValueFormatter(XAxisValueFormatter formatter): Sets a custom formatter for dynamically adjusting the x-values before drawing them. More information here.

Example Code

XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTextSize(10f);
xAxis.setTextColor(Color.RED);
xAxis.setDrawAxisLine(true);
xAxis.setDrawGridLines(false);
// set a custom value formatter
xAxis.setXValueFormatter(new MyCustomFormatter()); 
// and more...

The documentation has moved.

Clone this wiki locally