Class Sparkline

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.chart.Sparkline
All Implemented Interfaces:
Animation, Editable, StyleListener

public class Sparkline extends Component

A word sized chart for list rows, table cells and dashboards: a line, area or bar trend with no axes, legend or interaction, cheap enough to have hundreds on screen.

Container row = new Container(new BorderLayout());
Sparkline s = new Sparkline(3, 5, 4, 8, 7, 9).setType(Sparkline.AREA);
row.add(BorderLayout.EAST, s);

Sparklines in list rows

  • Field Details

  • Constructor Details

    • Sparkline

      public Sparkline(double... values)

      Creates a sparkline.

      Parameters
      • values: the values in order
  • Method Details

    • setValues

      public Sparkline setValues(double... v)

      Replaces the values.

      Parameters
      • v: the values in order
      Returns

      this sparkline

    • setType

      public Sparkline setType(int type)

      Chooses LINE, AREA or BARS.

      Parameters
      • type: the drawing type
      Returns

      this sparkline

    • setColor

      public Sparkline setColor(int rgb)

      Fixes the colour instead of the style's foreground.

      Parameters
      • rgb: the colour
      Returns

      this sparkline

    • setShowLast

      public Sparkline setShowLast(boolean b)

      Marks the last value with a dot.

      Parameters
      • b: true to mark it
      Returns

      this sparkline

    • setShowExtremes

      public Sparkline setShowExtremes(boolean b)

      Marks the highest and lowest values with dots in the positive and negative colours.

      Parameters
      • b: true to mark them
      Returns

      this sparkline

    • refreshTheme

      protected void refreshTheme(String id, boolean merge)
      Description copied from class: Component

      Makes sure the component is up to date with the given UIID

      Parameters
      • id: The Style Id to update the Component with

      • merge: indicates if the current styles should be merged with the new styles

      Overrides:
      refreshTheme in class Component
    • styleChanged

      public void styleChanged(String propertyName, Style source)
      Description copied from class: Component

      Invoked to indicate a change in a propertyName of a Style

      NOTE By default this will trigger a call to Container#revalidate() on the parent container, which is expensive. You can disable this behavior by calling CN.setProperty("Component.revalidateOnStyleChange", "false"). The intention is to change this behavior so that the default is to "not" revalidate on style change, so we encourage you to set this to "false" to ensure for future compatibility.

      Parameters
      • propertyName: the property name that was changed

      • source: The changed Style object

      Specified by:
      styleChanged in interface StyleListener
      Overrides:
      styleChanged in class Component
    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

      Returns

      the calculated preferred size based on component content

      Overrides:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

      Parameters
      • g: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component