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 allDataSets
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 allDataSets
this data object contains.setValueTypeface(Typeface tf)
: Sets theTypeface
for all value-labels for allDataSets
this data object contains.setValueFormatter(ValueFormatter f)
: Sets a customValueFormatter
for allDataSets
this data object contains, more on theValueFormatter
here.setDrawValues(boolean enabled)
: Enables / disables drawing values (value-text) for allDataSets
this data object contains.
Getters / Convenience
getDataSetByIndex(int index)
: Returns theDataSet
object at the given index in the data-objectsDataSet
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 providedDataSet
, false if not.
Clearing
clearValues()
: Clears the data object of allDataSet
objects and thereby allEntries
. Does not remove the provided x-values.
Highlighting
setHighlightEnabled(boolean enabled)
: Set this to true to allow highlighting via touch for thisChartData
object and all underlyingDataSets
.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.