Class JSparklinesTwoValueBarChartTableCellRenderer

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
no.uib.jsparklines.renderers.JSparklinesTwoValueBarChartTableCellRenderer
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, TableCellRenderer

public class JSparklinesTwoValueBarChartTableCellRenderer
extends JLabel
implements TableCellRenderer
Table cell renderer displaying JSparklines plots consisting of two values as a stacked bar charts. Supported input: XYDataPoint objects. Other object types are rendered using the DefaultTableCellRenderer.
Author:
Harald Barsnes
See Also:
Serialized Form
  • Constructor Details

    • JSparklinesTwoValueBarChartTableCellRenderer

      public JSparklinesTwoValueBarChartTableCellRenderer​(org.jfree.chart.plot.PlotOrientation plotOrientation, Double maxValue, Color firstValueColor, Color secondValueColor, boolean showFirstNumber)
      Creates a new JSparkLinesTableCellRenderer.
      Parameters:
      plotOrientation - the orientation of the plot
      maxValue - the maximum value to be plotted, used to make sure that all plots in the same column has the same maximum value and are thus comparable
      firstValueColor - the color to use for the first value
      secondValueColor - the color to use for the second value
      showFirstNumber - if true, the first value is shown when showing the values, false shows the sum
    • JSparklinesTwoValueBarChartTableCellRenderer

      public JSparklinesTwoValueBarChartTableCellRenderer​(org.jfree.chart.plot.PlotOrientation plotOrientation, Double maxValue, Color firstValueColor, Color secondValueColor, Color fillColor, boolean showFirstNumber)
      Creates a new JSparkLinesTableCellRenderer.
      Parameters:
      plotOrientation - the orientation of the plot
      maxValue - the maximum value to be plotted, used to make sure that all plots in the same column has the same maximum value and are thus comparable
      firstValueColor - the color to use for the first value
      secondValueColor - the color to use for the second value
      fillColor - the color used to fill the rest of the chart up to the max value (set to null if no filling should be used)
      showFirstNumber - if true, the first value is shown when showing the values, false shows the sum
  • Method Details

    • showNumberAndChart

      public void showNumberAndChart​(boolean showNumberAndChart, int widthOfLabel)
      If true the number will be shown together with the bar chart in the cell. False only display the chart.
      Parameters:
      showNumberAndChart - if true the number and the chart is shown in the cell
      widthOfLabel - the width used to display the label containing the number
    • showNumberAndChart

      public void showNumberAndChart​(boolean showNumberAndChart, int widthOfLabel, DecimalFormat numberFormat)
      If true the number will be shown together with the bar chart in the cell. False only display the chart.
      Parameters:
      showNumberAndChart - if true the number and the chart is shown in the cell
      widthOfLabel - the width used to display the label containing the number
      numberFormat - the decimal format to use when showing the numbers
    • showNumberAndChart

      public void showNumberAndChart​(boolean showNumberAndChart, int widthOfLabel, Font font, int horizontalAlignement)
      If true the number will be shown together with the bar chart in the cell. False only display the chart.
      Parameters:
      showNumberAndChart - if true the number and the chart is shown in the cell
      widthOfLabel - the width used to display the label containing the number
      font - the font to use for the label
      horizontalAlignement - the horizontal alignment of the text in the label: one of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.
    • showNumberAndChart

      public void showNumberAndChart​(boolean showNumberAndChart, int widthOfLabel, Font font, int horizontalAlignement, DecimalFormat numberFormat)
      If true the number will be shown together with the bar chart in the cell. False only display the chart.
      Parameters:
      showNumberAndChart - if true the number and the chart is shown in the cell
      widthOfLabel - the width used to display the label containing the number
      font - the font to use for the label
      horizontalAlignement - the horizontal alignment of the text in the label: one of the following constants defined in SwingConstants: LEFT, CENTER, RIGHT, LEADING or TRAILING.
      numberFormat - the decimal format to use when showing the numbers
    • showNumbers

      public void showNumbers​(boolean showNumbers)
      Set if the underlying numbers or the bar charts are to be shown.
      Parameters:
      showNumbers - if true the underlying numbers are shown
    • showFirstNumber

      public void showFirstNumber​(boolean showFirstNumber)
      If true, the first number is shown as the value. Otherwise the total value is shown.
      Parameters:
      showFirstNumber - show first number only?
    • getTableCellRendererComponent

      public Component getTableCellRendererComponent​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Specified by:
      getTableCellRendererComponent in interface TableCellRenderer
    • addReferenceLine

      public void addReferenceLine​(String label, double value, float lineWidth, Color lineColor)
      Add a reference line at a given data value.
      Parameters:
      label - the label for the reference
      value - the reference line value
      lineWidth - the line width, has to non-negative
      lineColor - the line color
    • addReferenceLine

      public void addReferenceLine​(ReferenceLine referenceLine)
      Add a reference line at a given data value.
      Parameters:
      referenceLine - the reference line
    • removeReferenceLine

      public void removeReferenceLine​(String label)
      Removes the reference line with the given label. Does nothing if no reference with the given label is found.
      Parameters:
      label - the reference to remove
    • removeAllReferenceLines

      public void removeAllReferenceLines()
      Removes all the reference lines.
    • getAllReferenceLines

      public HashMap<String,​ReferenceLine> getAllReferenceLines()
      Returns all the references lines as a hashmap, with the labels as the keys.
      Returns:
      hashmap of all reference lines
    • addReferenceArea

      public void addReferenceArea​(String label, double start, double end, Color areaColor, float alpha)
      Add a reference area.
      Parameters:
      label - the label for the reference area
      start - the start of the reference area
      end - the end of the reference area
      areaColor - the color of the reference area
      alpha - the alpha level of the reference area, range: 0.0 to 1.0
    • addReferenceArea

      public void addReferenceArea​(ReferenceArea referenceArea)
      Add a reference area.
      Parameters:
      referenceArea - the reference area
    • removeReferenceArea

      public void removeReferenceArea​(String label)
      Removes the reference area with the given label. Does nothing if no reference with the given label is found.
      Parameters:
      label - the reference to remove
    • removeAllReferenceAreas

      public void removeAllReferenceAreas()
      Removes all the reference areas.
    • getAllReferenceAreas

      public HashMap<String,​ReferenceArea> getAllReferenceAreas()
      Returns all the references areas as a hashmap, with the labels as the keys.
      Returns:
      hashmap of all reference areas
    • setMaxValue

      public void setMaxValue​(double maxValue)
      Set the maximum value.
      Parameters:
      maxValue - the maximum value
    • getFirstValueColor

      public Color getFirstValueColor()
      Get the color used for the first value in the charts.
      Returns:
      the color used for the first value in the charts
    • setFirstValueColor

      public void setFirstValueColor​(Color firstValueColor)
      Set the color used for the first value in the charts.
      Parameters:
      firstValueColor - the color to set
    • getSecondValueColor

      public Color getSecondValueColor()
      Get the color used for the second value in the charts.
      Returns:
      the color used for the second value in the charts
    • setSecondValueColor

      public void setSecondValueColor​(Color secondValueColor)
      Set the color used for the second value in the charts.
      Parameters:
      secondValueColor - the color to set
    • getPlotOrientation

      public org.jfree.chart.plot.PlotOrientation getPlotOrientation()
      Get the current plot orientation.
      Returns:
      the current plot orientation
    • setPlotOrientation

      public void setPlotOrientation​(org.jfree.chart.plot.PlotOrientation plotOrientation)
      Set the plot orientation.
      Parameters:
      plotOrientation - the new plot orientation
    • getChartPanel

      public org.jfree.chart.ChartPanel getChartPanel()
      Returns a reference to the chart panel.
      Returns:
      the chart panel.
    • setBackgroundColor

      public void setBackgroundColor​(Color color)
      Set the background color. If not set the background color of the given row will be used.
      Parameters:
      color - the new background color
    • getMaxValue

      public double getMaxValue()
      Returns the maximum value.
      Returns:
      the maxValue