Class Key


  • public class Key
    extends Object
    A Key can optionally be added to the Graph to display information about the data displayed on the Graph. At it's simplest you could do something like the following:
     AxesGraph graph = new AxesGraph();
     Series series = makeMySeries();
     graph.addSeries(series);
     graph.addKey(new Key(null), Align.BOTTOM);
     
    which will add all the series to the Graph. If you want more control over the contents off the key, calling the addSeries or addCustom, methods will clear the Key of any default values, allowing you to set the values as you see fit.
    See Also:
    Graph.addKey(org.faceless.graph2.Key, int)
    • Constructor Detail

      • Key

        public Key​(Style backstyle)
        Create a new Key
        Parameters:
        backstyle - the style to display the background box of the key in, or null not to display a box
    • Method Detail

      • setDefaultTextStyle

        public void setDefaultTextStyle​(TextStyle style)
        Set the default text style to use on the key. This is the style used if null is passed in as a style to addSeries or addCustom methods.
        Parameters:
        style - the default style to render the text in
      • addSeries

        public void addSeries​(Series series,
                              TextStyle style)
        Add the specified series to the Key. The text displayed next to the Series is the series name
        Parameters:
        series - the series to add to the Key
        style - The style to render the text in. May be null to use the default.
      • addCustom

        public void addCustom​(AbstractMarker marker,
                              String text,
                              TextStyle style)
        Add a custom marker and/or text to the Key.
        Parameters:
        marker - The marker to add to the Key. May be null to display only text.
        text - The text to add to the Key. May be null to display only the marker.
        style - The style to render the text in. May be null to use the default.
        Since:
        2.4
      • setMaxWidth

        public void setMaxWidth​(int width)
        Set the maximum width of the Key box. To display Keys vertically in a single column set this value to 0.
        Parameters:
        width - the maximum width of the key box, in pixels or whatever measurement is used by your Output object.
      • setMargin

        public void setMargin​(int margin)
        Set the margin around the Key. The margin is the space between the outside edge of the Key box and the edge of the graph itself if the key is positioned at the edge of the box using the Graph.addKey(Key,int) method. The default is 10.
        Parameters:
        margin - the margin to use around the key box, in pixels or whatever measurement is used by your Output object.
      • setMargin

        public void setMargin​(int top,
                              int right,
                              int bottom,
                              int left)
        Set the margin around the Key. The margin is the space between the outside edge of the Key box and the edge of the graph itself if the key is positioned at the edge of the box using the Graph.addKey(Key,int) method. The default is 10 for each
        Parameters:
        top - the margin to use at the top of the key box, in pixels or whatever measurement is used by your Output object.
        right - the margin to use at the right of the key box, in pixels or whatever measurement is used by your Output object.
        bottom - the margin to use at the bottom of the key box, in pixels or whatever measurement is used by your Output object.
        left - the margin to use at the left of the key box, in pixels or whatever measurement is used by your Output object.
      • setPadding

        public void setPadding​(int padding)
        Set the padding for the Key. The padding is the space between the inside edge of the Key box and the actual contents of the Key. The default is 7.
        Parameters:
        padding - the padding to use inside the key box, in pixels or whatever measurement is used by your Output object.
      • setPadding

        public void setPadding​(int top,
                               int right,
                               int bottom,
                               int left)
        Set the padding for the Key. The padding is the space between the inside edge of the Key box and the actual contents of the Key. The default is 7 for each parameter.
        Parameters:
        top - the padding to use inside at the top of the key box, in pixels or whatever measurement is used by your Output object.
        right - the padding to use inside at the right of the key box, in pixels or whatever measurement is used by your Output object.
        bottom - the padding to use inside at the bottom of the key box, in pixels or whatever measurement is used by your Output object.
        left - the padding to use inside at the left of the key box, in pixels or whatever measurement is used by your Output object.
      • setVerticalAdvance

        public void setVerticalAdvance​(int advance)
        Set the vertical padding to place between each line in the key
      • setHorizontalAdvance

        public void setHorizontalAdvance​(int advance)
        Set the horizontal padding to place between each item on the same line