-
public class Legend extends ComponentBase
Class representing the legend of the chart. The legend will contain one entry per color and DataSet. Multiple colors in one DataSet are grouped together. The legend object is NOT available before setting data to the chart.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumLegend.LegendFormpublic enumLegend.LegendHorizontalAlignmentpublic enumLegend.LegendVerticalAlignmentpublic enumLegend.LegendOrientationpublic enumLegend.LegendDirection
-
Field Summary
Fields Modifier and Type Field Description public floatmNeededWidthpublic floatmNeededHeightpublic floatmTextHeightMaxpublic floatmTextWidthMax
-
Constructor Summary
Constructors Constructor Description Legend()default constructor Legend(Array<LegendEntry> entries)Constructor.
-
Method Summary
Modifier and Type Method Description voidsetEntries(List<LegendEntry> entries)This method sets the automatically computed colors for the legend. Array<LegendEntry>getEntries()floatgetMaximumEntryWidth(Paint p)returns the maximum length in pixels across all legend labels + formsize+ formtotextspace floatgetMaximumEntryHeight(Paint p)returns the maximum height in pixels across all legend labels Array<LegendEntry>getExtraEntries()voidsetExtra(List<LegendEntry> entries)voidsetExtra(Array<LegendEntry> entries)voidsetExtra(Array<int> colors, Array<String> labels)Entries that will be appended to the end of the auto calculatedentries after calculating the legend. voidsetCustom(Array<LegendEntry> entries)Sets a custom legend's entries array.* A null label will start a group.This will disable the feature that automatically calculates the legendentries from the datasets. voidsetCustom(List<LegendEntry> entries)Sets a custom legend's entries array.* A null label will start a group.This will disable the feature that automatically calculates the legendentries from the datasets. voidresetCustom()Calling this will disable the custom legend entries (set bysetCustom(...)). booleanisLegendCustom()Legend.LegendHorizontalAlignmentgetHorizontalAlignment()returns the horizontal alignment of the legend voidsetHorizontalAlignment(Legend.LegendHorizontalAlignment value)sets the horizontal alignment of the legend Legend.LegendVerticalAlignmentgetVerticalAlignment()returns the vertical alignment of the legend voidsetVerticalAlignment(Legend.LegendVerticalAlignment value)sets the vertical alignment of the legend Legend.LegendOrientationgetOrientation()returns the orientation of the legend voidsetOrientation(Legend.LegendOrientation value)sets the orientation of the legend booleanisDrawInsideEnabled()returns whether the legend will draw inside the chart or outside voidsetDrawInside(boolean value)sets whether the legend will draw inside the chart or outside Legend.LegendDirectiongetDirection()returns the text direction of the legend voidsetDirection(Legend.LegendDirection pos)sets the text direction of the legend Legend.LegendFormgetForm()returns the current form/shape that is set for the legend voidsetForm(Legend.LegendForm shape)sets the form/shape of the legend forms voidsetFormSize(float size)sets the size in dp of the legend forms, default 8f floatgetFormSize()returns the size in dp of the legend forms voidsetFormLineWidth(float size)sets the line width in dp for forms that consist of lines, default 3f floatgetFormLineWidth()returns the line width in dp for drawing forms that consist of lines voidsetFormLineDashEffect(DashPathEffect dashPathEffect)Sets the line dash path effect used for shapes that consist of lines. DashPathEffectgetFormLineDashEffect()floatgetXEntrySpace()returns the space between the legend entries on a horizontal axis inpixels voidsetXEntrySpace(float space)sets the space between the legend entries on a horizontal axis in pixels,converts to dp internally floatgetYEntrySpace()returns the space between the legend entries on a vertical axis in pixels voidsetYEntrySpace(float space)sets the space between the legend entries on a vertical axis in pixels,converts to dp internally floatgetFormToTextSpace()returns the space between the form and the actual label/text voidsetFormToTextSpace(float space)sets the space between the form and the actual label/text, converts to dpinternally floatgetStackSpace()returns the space that is left out between stacked forms (with no label) voidsetStackSpace(float space)sets the space that is left out between stacked forms (with no label) voidsetWordWrapEnabled(boolean enabled)Should the legend word wrap? booleanisWordWrapEnabled()If this is set, then word wrapping the legend is enabled. floatgetMaxSizePercent()The maximum relative size out of the whole chart view. voidsetMaxSizePercent(float maxSize)The maximum relative size out of the whole chart view. List<FSize>getCalculatedLabelSizes()List<Boolean>getCalculatedLabelBreakPoints()List<FSize>getCalculatedLineSizes()voidcalculateDimensions(Paint labelpaint, ViewPortHandler viewPortHandler)Calculates the dimensions of the Legend. -
Methods inherited from class com.github.mikephil.charting.components.ComponentBase
getTextColor, getTextSize, getTypeface, getXOffset, getYOffset, isEnabled, setEnabled, setTextColor, setTextSize, setTypeface, setXOffset, setYOffset -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
Legend
Legend()
default constructor
-
Legend
Legend(Array<LegendEntry> entries)
Constructor.
-
-
Method Detail
-
setEntries
void setEntries(List<LegendEntry> entries)
This method sets the automatically computed colors for the legend. Use setCustom(...) to set custom colors.
-
getEntries
Array<LegendEntry> getEntries()
-
getMaximumEntryWidth
float getMaximumEntryWidth(Paint p)
returns the maximum length in pixels across all legend labels + formsize+ formtotextspace
- Parameters:
p- the paint object used for rendering the text
-
getMaximumEntryHeight
float getMaximumEntryHeight(Paint p)
returns the maximum height in pixels across all legend labels
- Parameters:
p- the paint object used for rendering the text
-
getExtraEntries
Array<LegendEntry> getExtraEntries()
-
setExtra
void setExtra(List<LegendEntry> entries)
-
setExtra
void setExtra(Array<LegendEntry> entries)
-
setExtra
void setExtra(Array<int> colors, Array<String> labels)
Entries that will be appended to the end of the auto calculatedentries after calculating the legend.(if the legend has already been calculated, you will need to call notifyDataSetChanged()to let the changes take effect)
-
setCustom
void setCustom(Array<LegendEntry> entries)
Sets a custom legend's entries array.* A null label will start a group.This will disable the feature that automatically calculates the legendentries from the datasets.Call resetCustom() to re-enable automatic calculation (and thennotifyDataSetChanged() is needed to auto-calculate the legend again)
-
setCustom
void setCustom(List<LegendEntry> entries)
Sets a custom legend's entries array.* A null label will start a group.This will disable the feature that automatically calculates the legendentries from the datasets.Call resetCustom() to re-enable automatic calculation (and thennotifyDataSetChanged() is needed to auto-calculate the legend again)
-
resetCustom
void resetCustom()
Calling this will disable the custom legend entries (set bysetCustom(...)). Instead, the entries will again be calculatedautomatically (after notifyDataSetChanged() is called).
-
isLegendCustom
boolean isLegendCustom()
-
getHorizontalAlignment
Legend.LegendHorizontalAlignment getHorizontalAlignment()
returns the horizontal alignment of the legend
-
setHorizontalAlignment
void setHorizontalAlignment(Legend.LegendHorizontalAlignment value)
sets the horizontal alignment of the legend
-
getVerticalAlignment
Legend.LegendVerticalAlignment getVerticalAlignment()
returns the vertical alignment of the legend
-
setVerticalAlignment
void setVerticalAlignment(Legend.LegendVerticalAlignment value)
sets the vertical alignment of the legend
-
getOrientation
Legend.LegendOrientation getOrientation()
returns the orientation of the legend
-
setOrientation
void setOrientation(Legend.LegendOrientation value)
sets the orientation of the legend
-
isDrawInsideEnabled
boolean isDrawInsideEnabled()
returns whether the legend will draw inside the chart or outside
-
setDrawInside
void setDrawInside(boolean value)
sets whether the legend will draw inside the chart or outside
-
getDirection
Legend.LegendDirection getDirection()
returns the text direction of the legend
-
setDirection
void setDirection(Legend.LegendDirection pos)
sets the text direction of the legend
-
getForm
Legend.LegendForm getForm()
returns the current form/shape that is set for the legend
-
setForm
void setForm(Legend.LegendForm shape)
sets the form/shape of the legend forms
-
setFormSize
void setFormSize(float size)
sets the size in dp of the legend forms, default 8f
-
getFormSize
float getFormSize()
returns the size in dp of the legend forms
-
setFormLineWidth
void setFormLineWidth(float size)
sets the line width in dp for forms that consist of lines, default 3f
-
getFormLineWidth
float getFormLineWidth()
returns the line width in dp for drawing forms that consist of lines
-
setFormLineDashEffect
void setFormLineDashEffect(DashPathEffect dashPathEffect)
Sets the line dash path effect used for shapes that consist of lines.
-
getFormLineDashEffect
DashPathEffect getFormLineDashEffect()
-
getXEntrySpace
float getXEntrySpace()
returns the space between the legend entries on a horizontal axis inpixels
-
setXEntrySpace
void setXEntrySpace(float space)
sets the space between the legend entries on a horizontal axis in pixels,converts to dp internally
-
getYEntrySpace
float getYEntrySpace()
returns the space between the legend entries on a vertical axis in pixels
-
setYEntrySpace
void setYEntrySpace(float space)
sets the space between the legend entries on a vertical axis in pixels,converts to dp internally
-
getFormToTextSpace
float getFormToTextSpace()
returns the space between the form and the actual label/text
-
setFormToTextSpace
void setFormToTextSpace(float space)
sets the space between the form and the actual label/text, converts to dpinternally
-
getStackSpace
float getStackSpace()
returns the space that is left out between stacked forms (with no label)
-
setStackSpace
void setStackSpace(float space)
sets the space that is left out between stacked forms (with no label)
-
setWordWrapEnabled
void setWordWrapEnabled(boolean enabled)
Should the legend word wrap? / this is currently supported only for:BelowChartLeft, BelowChartRight, BelowChartCenter. / note that wordwrapping a legend takes a toll on performance. / you may want to setmaxSizePercent when word wrapping, to set the point where the text wraps./ default: false
-
isWordWrapEnabled
boolean isWordWrapEnabled()
If this is set, then word wrapping the legend is enabled. This means thelegend will not be cut off if too long.
-
getMaxSizePercent
float getMaxSizePercent()
The maximum relative size out of the whole chart view. / If the legend isto the right/left of the chart, then this affects the width of thelegend. / If the legend is to the top/bottom of the chart, then thisaffects the height of the legend. / If the legend is the center of thepiechart, then this defines the size of the rectangular bounds out of thesize of the "hole". / default: 0.95f (95%)
-
setMaxSizePercent
void setMaxSizePercent(float maxSize)
The maximum relative size out of the whole chart view. / Ifthe legend is to the right/left of the chart, then this affects the widthof the legend. / If the legend is to the top/bottom of the chart, thenthis affects the height of the legend. / default: 0.95f (95%)
-
getCalculatedLabelSizes
List<FSize> getCalculatedLabelSizes()
-
getCalculatedLabelBreakPoints
List<Boolean> getCalculatedLabelBreakPoints()
-
getCalculatedLineSizes
List<FSize> getCalculatedLineSizes()
-
calculateDimensions
void calculateDimensions(Paint labelpaint, ViewPortHandler viewPortHandler)
Calculates the dimensions of the Legend. This includes the maximum widthand height of a single entry, as well as the total width and height ofthe Legend.
-
-
-
-