Skip to content

Highlighting

Philipp Jahoda edited this page Aug 6, 2016 · 17 revisions

This section focuses on the topic of highlighting entries in the chart, both via tap-gesture and programmatically.

Highlighting programmatically

  • highlightValues(Highlight[] highs): Highlights the values at the given indices in the given DataSets. Provide null or an empty array to undo all highlighting.
  • highlightValue(int xIndex, int dataSetIndex): Highlights the value at the given x-index in the given DataSet. Provide -1 as the x-index or dataSetIndex to undo all highlighting.
  • getHighlighted(): Returns an Highlight[] array that contains information about all highlighted entries, their x-index and dataset-index.

Highlighting values programmatically will not generate a callback to the OnChartValueSelectedListener. Enabling and disabling highlighting can be done via ChartData or DataSet object.

Custom highlighter

All user input in the form of highlight gestures is internally processed by the default ChartHighlighter class. It is possible to replace the default highligher with a custom implementation using the below method:

  • setHighlighter(ChartHighlighter highlighter): Sets a custom highligher object for the chart that handles / processes all highlight touch events performed on the chart-view. Your custom highlighter object needs to extend the ChartHighlighter class.

Selection callbacks

This library provides a number of listeners for callbacks upon interaction. One of them is the OnChartValueSelectedListener, for callbacks when highlighting values via touch:

public interface OnChartValueSelectedListener {
    /**
    * Called when a value has been selected inside the chart.
    *
    * @param e The selected Entry.
    * @param h The corresponding highlight object that contains information
    * about the highlighted position
    */
    public void onValueSelected(Entry e, Highlight h);
    /**
    * Called when nothing has been selected or an "un-select" has been made.
    */
    public void onNothingSelected();
}

Simply let your class that should receive the callbacks implement this interface and set it as a listener to the chart:

chart.setOnChartValueSelectedListener(this);

The documentation has moved.

Clone this wiki locally