This wiki entry is intended to provide better insight into the data model behind MPAndroidChart.

The ChartData class is the baseclass of all data classes (subclasses), like LineData, BarData, … and so on. It is used to provide data for the Chart via the setData(...) method of the chart.

public class LineData extends ChartData { ...

The following mentioned methods are implemented in the ChartData class and can therefore be used for all subclasses.

Styling data

  • setValueTextColor(int color): Sets the color of the value-text (color in which the value-labels are drawn) for all DataSets this data object contains.
  • setValueTextColors(List<Integer> colors): Sets a list of colors to be used as value colors.
  • setValueTextSize(float size): Sets the size (in dp) of the value-text for all DataSets this data object contains.
  • setValueTypeface(Typeface tf): Sets the Typeface for all value-labels for all DataSets this data object contains.
  • setValueFormatter(ValueFormatter f): Sets a custom ValueFormatter for all DataSets this data object contains, more on the ValueFormatter here.
  • setDrawValues(boolean enabled): Enables / disables drawing values (value-text) for all DataSets this data object contains.

Getters / Convenience

  • getDataSetByIndex(int index): Returns the DataSet object at the given index in the data-objects DataSet list.
  • contains(Entry entry): Checks if this data object contains the specified Entry. Returns true if so, false if not. NOTE: Performance is pretty bad on this one, do not over-use in performance critical situations.
  • contains(T dataSet): Returns true if this data object contains the provided DataSet, false if not.

Clearing

  • clearValues(): Clears the data object of all DataSet objects and thereby all Entries. Does not remove the provided x-values.

Highlighting

  • setHighlightEnabled(boolean enabled): Set this to true to allow highlighting via touch for this ChartData object and all underlying DataSets.
  • setDrawVerticalHighlightIndicator(boolean enabled): Enables / disables the vertical highlight-indicator-line. If disabled, the indicator is not drawn.
  • setDrawHorizontalHighlightIndicator(boolean enabled): Enables / disables the horizontal highlight-indicator-line. If disabled, the indicator is not drawn.

Dynamic Data

  • notifyDataChanged(): Lets the data object know it’s underlying data has changed and performs all necessary recalculations.

For ways of adding and removing data from an existing data object, please visit the dynamic & realtime data section.

Close Menu