Axis labels behavior insights

Axis labels behavior insights

Generally, there are two ways to make ChartAxis render labels:

Add labels manually.

ChartAxis exposes chart labels collection via ChartAxis.getCustomLabels(). Returned collection can be used to add your own axis labels. No formatting is applied to the text of custom labels. In order to show only custom labels, disable automatic labels via ChartAxis.setLabelsAdapter(null)

Automatic labels generation.

This mode is enabled by default and ChartAxis will try to determine the most appropriate way to render labels. Automatic labels generation is affected by following parameters:
  • ChartAxis.setValueType()/getValueType() - identifies type of data that this axis operates on. Affects axis ranges calculation, labels intervals, gridlines intervals, etc.
  • ChartAxis.getLabelsAdapter() - identifies algorithm used to generate labels
    • null value - automatic labels generation is disabled. This setting mostly used with manual labels generation described above.
    • ChartAxis.DEFAULT_LABELS_ADAPTER - labels generated with respect to axis range and interval.
    • ChartAxis.SERIES_LABELS_ADAPTER - labels generated with respect to actual ChartPoints added to series. Label text can be applied via ChartPoint.setAxisLabel or generated based on ChartPoint.getx()/setX().
    • ChartAxis.SMART_LABELS_ADAPTER - the same as ChartAxis.SERIES_LABELS_ADAPTER, but after generation, labels get filtered to match ChartAxis.getScale().getVisibleInterval() minimum distance.
    You may also implement you algorithm via ChartAxis.LabelsAdapter interface.
  • ChartAxis.getScale() exposes instance of ChartAxisScale class that allows control over intervals quantity, distance between them, gridlines interval, ect. APIs to consider:
    • getDesiredIntervalCount()/setDesiredIntervalCount() - determines desired intervals count. Actual quantity of intervals depends on margin exposed via getMargin()/setMargin() methods.
    • setInterval() - sets particular value of axis's interval. Usually used in conjunction with ChartAxis.ValueType.Date data type. When interval is set, DesiredIntervalCount property is ignored.
  • ChartAxis.setFormat()/getFormat() - sets formatting object for labels. aiCharts provides following implementations of labels formatter: NumberFormat(DecimalFormat\ChoiceFormat), DateFormat (SimpleDateFormat) and MessageFormat (via single-value-array).
↑ Go to top