Package 

Class Legend


  • 
    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.

    • Constructor Detail

      • Legend

        Legend()
        default 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.

      • 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
      • 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).

      • 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

      • 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

      • 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%)

      • 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.