-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Highlighting
This section focuses on the topic of highlighting entries in the chart, both via tap-gesture and programmatically.
###Enabling / Disabling highlighting
-
setHighlightPerDragEnabled(boolean enabled)
: Set this to true to allow highlighting per dragging over the chart surface when it is fully zoomed out. Default: true -
setHighlightPerTapEnabled(boolean enabled)
: Set this to false to prevent values from being highlighted by tap gesture. Values can still be highlighted via drag or programmatically. Default: true
In addition to that, highlighting can be enabled / disabled for individual DataSet
objects.
###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 anHighlight[]
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 theChartHighlighter
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);