-
-
Notifications
You must be signed in to change notification settings - Fork 9k
YAxis
The YAxis
is a subclass of AxisBase. This wiki entry only describes the YAxis
, not it's superclass.
The YAxis
class (in versions older than 2.0.0 YLabels
called), is the data and information container for everything related with the vertical-axis. Each Line-, Bar-, Scatter or CandleStickChart has a left and a right YAxis
object, responsible for either the left, or the right axis respectively. The RadarChart has only one YAxis
. By default, both axes of the chart are enabled and will be drawn.
In order to acquire an instance of the YAxis
class, call one of the following methods:
YAxis leftAxis = chart.getAxisLeft();
YAxis rightAxis = chart.getAxisRight();
YAxis leftAxis = chart.getAxis(AxisDependency.LEFT);
YAxis yAxis = radarChart.getYAxis(); // this method radarchart only
At runtime, use public AxisDependency getAxisDependency()
to determine the side of the chart this axis represents.
Customizations that affect the value range of the axis need to be applied before setting data for the chart.
Custom formatting for axis labels
-
setValueFormatter(YAxisValueFormatterf)
: Sets a customValueFormatter
for this axis. This interface allows to format/modify the original label text and instead return a customized text. More on theYAxisValueFormatter
here.
The zero line
Besides the grid-lines, that originate horizontally alongside each value on the YAxis
, there is the so called zeroline, which is drawn at the zero (0) value on the axis, and is similar to the grid-lines but can be configured separately.
-
setDrawZeroLine(boolean enabled)
: Enables / disables drawing the zero-line. -
setZeroLineWidth(float width)
: Sets the line-width of the zero line. -
setZeroLineColor(int color)
: Sets the color the zero-line should have.
Zero-line example code:
// data has AxisDependency.LEFT
YAxis left = mChart.getAxisLeft();
left.setDrawLabels(false); // no axis labels
left.setDrawAxisLine(false); // no axis line
left.setDrawGridLines(false); // no grid lines
left.setDrawZeroLine(true); // draw a zero line
mChart.getAxisRight().setEnabled(false); // no right axis
The above code will result in a zero-line like shown in the image below. No axis values are drawn, no grid lines or axis lines are drawn, just a zero line.
More example code
YAxis yAxis = mChart.getAxisLeft();
yAxis.setTypeface(...); // set a different font
yAxis.setTextSize(12f); // set the textsize
yAxis.setAxisMaxValue(100f); // the axis maximum is 100
yAxis.setTextColor(Color.BLACK);
yAxis.setValueFormatter(new MyValueFormatter());
yAxis.setLabelCount(6, true); // force 6 labels
//... and more