eu.webtoolkit.jwt.chart
Class WAxis

java.lang.Object
  extended by eu.webtoolkit.jwt.chart.WAxis

public class WAxis
extends java.lang.Object

Class which represents an axis of a cartesian chart.

A cartesian chart has two or three axes: an X axis (XAxis ), a Y axis (YAxis) and optionally a second Y axis ( Y2Axis). Each of the up to three axes in a cartesian chart has a unique getId() that identifies which of these three axes it is in the enclosing getChart().

Use setVisible() to change the visibility of an axis, setGridLinesEnabled() to show grid lines for an axis. The pen styles for rendering the axis or grid lines may be changed using setPen() and setGridLinesPen(). A margin between the axis and the main plot area may be configured using setMargin().

By default, the axis will automatically adjust its range so that all data will be visible. You may manually specify a range using setMinimum(), setMaximum or setRange(). The interval between labels is by default automatically adjusted depending on the axis length and the range, but may be manually specified using setLabelInterval().

The axis has support for being "broken", to support displaying data with a few outliers which would otherwise swamp the chart. This is not done automatically, but instead you need to use setBreak() to specify the value range that needs to be omitted from the axis. The omission is rendered in the axis and in bars that cross the break.

The labels are shown using a "%.4g" format string for numbers, and "dd/MM/yyyy" (for DateScale). The format may be customized using setLabelFormat(). The angle of the label text may be changed using setLabelAngle(). By default, all labels are printed horizontally.

See Also:
WCartesianChart

Field Summary
static double AUTO_MAXIMUM
          Constant which indicates automatic maximum calculation.
static double AUTO_MINIMUM
          Constant which indicates automatic minimum calculation.
 
Method Summary
 java.util.EnumSet<AxisValue> getAutoLimits()
          Returns the limits that are calculated automatically.
 WCartesianChart getChart()
          Returns the chart to which this axis belongs.
 WPen getGridLinesPen()
          Returns the pen used for rendering the grid lines.
 Axis getId()
          Returns the axis id.
 double getLabelAngle()
          Returns the label angle.
 WFont getLabelFont()
          Returns the axis label font.
 WString getLabelFormat()
          Returns the label format string.
 double getLabelInterval()
          Returns the label interval.
 AxisValue getLocation()
          Returns the axis location.
 int getMargin()
          Returns the margin between the axis and the plot area.
 double getMaximum()
          Returns the maximum value displayed on the axis.
 double getMinimum()
          Returns the minimum value displayed on the axis.
 WPen getPen()
          Returns the pen used for rendering the axis and ticks.
 double getResolution()
          Returns the axis resolution.
 AxisScale getScale()
          Returns the scale of the axis.
 WString getTitle()
          Returns the axis title.
 WFont getTitleFont()
          Returns the axis title font.
 boolean isGridLinesEnabled()
          Returns whether gridlines are displayed for this axis.
 boolean isVisible()
          Returns whether this axis is visible.
 void setAutoLimits(AxisValue location, AxisValue... locations)
          Let the minimum and/or maximum be calculated from the data.
 void setAutoLimits(java.util.EnumSet<AxisValue> locations)
          Let the minimum and/or maximum be calculated from the data.
 void setBreak(double minimum, double maximum)
          Specify a range that needs to be omitted from the axis.
 void setGridLinesEnabled(boolean enabled)
          Sets whether gridlines are displayed for this axis.
 void setGridLinesPen(WPen pen)
          Changes the pen used for rendering the grid lines.
 void setLabelAngle(double angle)
          Sets the label angle.
 void setLabelFont(WFont labelFont)
          Sets the axis label font.
 void setLabelFormat(java.lang.CharSequence format)
          Sets the label format.
 void setLabelInterval(double labelInterval)
          Sets the label interval.
 void setLocation(AxisValue location)
          Sets the axis location.
 void setMargin(int pixels)
          Sets the margin between the axis and the plot area.
 void setMaximum(double maximum)
          Sets the maximum value for the axis displayed on the axis.
 void setMinimum(double minimum)
          Sets the minimum value displayed on the axis.
 void setPen(WPen pen)
          Changes the pen used for rendering the axis and ticks.
 void setRange(double minimum, double maximum)
          Sets the axis range (minimum and maximum values) manually.
 void setResolution(double resolution)
          Sets the axis resolution.
 void setScale(AxisScale scale)
          Sets the scale of the axis.
 void setTitle(java.lang.CharSequence title)
          Sets the axis title.
 void setTitleFont(WFont titleFont)
          Sets the axis title font.
 void setVisible(boolean visible)
          Sets whether this axis is visible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUTO_MINIMUM

public static final double AUTO_MINIMUM
Constant which indicates automatic minimum calculation.

See Also:
setMinimum(double minimum), Constant Field Values

AUTO_MAXIMUM

public static final double AUTO_MAXIMUM
Constant which indicates automatic maximum calculation.

See Also:
setMaximum(double maximum), Constant Field Values
Method Detail

getId

public Axis getId()
Returns the axis id.

See Also:
getChart(), WCartesianChart.getAxis(Axis axis)

setVisible

public void setVisible(boolean visible)
Sets whether this axis is visible.

Changes whether the axis is displayed, including ticks and labels. The rendering of the grid lines is controlled seperately by setGridLinesEnabled().

The default value is true for the X axis and first Y axis, but false for the second Y axis.

See Also:
setGridLinesEnabled(boolean enabled)

isVisible

public boolean isVisible()
Returns whether this axis is visible.

See Also:
setVisible(boolean visible)

setLocation

public void setLocation(AxisValue location)
Sets the axis location.

Configures the location of the axis, relative to values on the other axis (i.e. Y values for the X axis, and X values for the Y axis).

The default value is AxisValue.MinimumValue.

See Also:
getLocation()

getLocation

public AxisValue getLocation()
Returns the axis location.

See Also:
setLocation(AxisValue location)

setScale

public void setScale(AxisScale scale)
Sets the scale of the axis.

For the X scale in a CategoryChart, the scale should be left unchanged to CategoryScale.

For all other axes, the default value is LinearScale, but this may be changed to LogScale or DateScale. DateScale is only useful for the X axis in a ScatterPlot which contains WDate values.

See Also:
getScale()

getScale

public AxisScale getScale()
Returns the scale of the axis.

See Also:
setScale(AxisScale scale)

setMinimum

public void setMinimum(double minimum)
Sets the minimum value displayed on the axis.

Specify the minimum value to be displayed on the axis. By default, the minimum and maximum values are determined automatically so that all the data can be displayed.

The numerical value corresponding to a data point is defined by it's AxisScale type.

See Also:
getMinimum(), setMaximum(double maximum)

getMinimum

public double getMinimum()
Returns the minimum value displayed on the axis.

This returned the minimum value that was set using setMinimum(), or otherwise the automatically calculated minimum.

The numerical value corresponding to a data point is defined by it's AxisScale type.

See Also:
getMaximum(), setMinimum(double minimum), setAutoLimits(EnumSet locations)

setMaximum

public void setMaximum(double maximum)
Sets the maximum value for the axis displayed on the axis.

Specify the maximum value to be displayed on the axis. By default, the minimum and maximum values are determined automatically so that all the data can be displayed.

The numerical value corresponding to a data point is defined by it's AxisScale type.

See Also:
getMinimum(), setMinimum(double minimum)

getMaximum

public double getMaximum()
Returns the maximum value displayed on the axis.

This returned the maximum value that was set using setMaximum(), or otherwise the automatically calculated maximum.

The numerical value corresponding to a data point is defined by it's AxisScale type.

See Also:
getMinimum(), setMaximum(double maximum)

setRange

public void setRange(double minimum,
                     double maximum)
Sets the axis range (minimum and maximum values) manually.

Specifies both minimum and maximum value for the axis. This automatically disables automatic range calculation.

The numerical value corresponding to a data point is defined by it's AxisScale type.

See Also:
setMinimum(double minimum), setMaximum(double maximum)

setResolution

public void setResolution(double resolution)
Sets the axis resolution.

Specifies the axis resolution, in case maximum-minimum < resolution minimum and maximum are modified so the maximum - minimum = resolution

The default resolution is 0, which uses a built-in epsilon.

See Also:
getResolution()

getResolution

public double getResolution()
Returns the axis resolution.

See Also:
setResolution(double resolution)

setAutoLimits

public void setAutoLimits(java.util.EnumSet<AxisValue> locations)
Let the minimum and/or maximum be calculated from the data.

Using this method, you can indicate that you want to have automatic limits, rather than limits set manually using setMinimum() or setMaximum().

locations can be AxisValue.MinimumValue and/or AxisValue.MaximumValue.

The default value is AxisValue.MinimumValue | AxisValue.MaximumValue.


setAutoLimits

public final void setAutoLimits(AxisValue location,
                                AxisValue... locations)
Let the minimum and/or maximum be calculated from the data.

Calls setAutoLimits(EnumSet.of(location, locations))


getAutoLimits

public java.util.EnumSet<AxisValue> getAutoLimits()
Returns the limits that are calculated automatically.

This returns the limits (AxisValue.MinimumValue and/or AxisValue.MaximumValue) that are calculated automatically from the data, rather than being specified manually using setMinimum() and/or setMaximum().

See Also:
setAutoLimits(EnumSet locations)

setBreak

public void setBreak(double minimum,
                     double maximum)
Specify a range that needs to be omitted from the axis.

This is useful to display data with a few outliers which would otherwise swamp the chart. This is not done automatically, but instead you need to use setBreak() to specify the value range that needs to be omitted from the axis. The omission is rendered in the axis and in BarSeries that cross the break.


setLabelInterval

public void setLabelInterval(double labelInterval)
Sets the label interval.

Specifies the interval for displaying labels (and ticks) on the axis. The default value is 0.0, and indicates that the interval should be computed automatically.

See Also:
setLabelFormat(CharSequence format)

getLabelInterval

public double getLabelInterval()
Returns the label interval.

See Also:
setLabelInterval(double labelInterval)

setLabelFormat

public void setLabelFormat(java.lang.CharSequence format)
Sets the label format.

Sets a format string which is used to format values, both for the axis labels as well as data series values (see WDataSeries#setLabelsEnabled()).

For an axis with a LinearScale or LogScale scale, the format string must be a format string that is accepted by snprintf() and which formats one double. If the format string is an empty string, "%.4g" is used.

For an axis with a DateScale scale, the format string must be a format string accepted by WDate::toString(const WString&), to format a date. If the format string is an empty string, "dd/MM/yyyy", "MMM yy" or "yyyy" is used depending on the situation.

The default value is an empty string ("").

See Also:
getLabelFormat()

getLabelFormat

public WString getLabelFormat()
Returns the label format string.

See Also:
setLabelFormat(CharSequence format)

setLabelAngle

public void setLabelAngle(double angle)
Sets the label angle.

Sets the angle used for displaying the labels (in degrees). A 0 angle corresponds to horizontal text. Note that this option is only supported by the InlineSvgVml renderers, but not by HtmlCanvas.

The default value is 0.0 ("horizontal text").

See Also:
getLabelAngle()

getLabelAngle

public double getLabelAngle()
Returns the label angle.

See Also:
setLabelAngle(double angle)

setGridLinesEnabled

public void setGridLinesEnabled(boolean enabled)
Sets whether gridlines are displayed for this axis.

When enabled, gird lines are drawn for each tick on this axis, using the getGridLinesPen().

Unlike all other visual aspects of an axis, rendering of the gridlines is not controlled by setDisplayEnabled(bool).

See Also:
setGridLinesPen(WPen pen), isGridLinesEnabled()

isGridLinesEnabled

public boolean isGridLinesEnabled()
Returns whether gridlines are displayed for this axis.

See Also:
setGridLinesEnabled(boolean enabled)

setPen

public void setPen(WPen pen)
Changes the pen used for rendering the axis and ticks.

The default value is a black pen of 0 width.

See Also:
setGridLinesPen(WPen pen)

getPen

public WPen getPen()
Returns the pen used for rendering the axis and ticks.

See Also:
setPen(WPen pen)

setGridLinesPen

public void setGridLinesPen(WPen pen)
Changes the pen used for rendering the grid lines.

The default value is a gray pen of 0 width.

See Also:
setPen(WPen pen), getGridLinesPen()

getGridLinesPen

public WPen getGridLinesPen()
Returns the pen used for rendering the grid lines.

See Also:
setGridLinesPen(WPen pen)

setMargin

public void setMargin(int pixels)
Sets the margin between the axis and the plot area.

The margin is defined in pixels.

The default value is 0.

See Also:
getMargin()

getMargin

public int getMargin()
Returns the margin between the axis and the plot area.

See Also:
setMargin(int pixels)

setTitle

public void setTitle(java.lang.CharSequence title)
Sets the axis title.

The default title is empty.

See Also:
getTitle()

getTitle

public WString getTitle()
Returns the axis title.

See Also:
setTitle(CharSequence title)

setTitleFont

public void setTitleFont(WFont titleFont)
Sets the axis title font.

The default title font is a 12 point Sans Serif font.

See Also:
getTitleFont()

getTitleFont

public WFont getTitleFont()
Returns the axis title font.

See Also:
setTitleFont(WFont titleFont)

setLabelFont

public void setLabelFont(WFont labelFont)
Sets the axis label font.

The default label font is a 10 point Sans Serif font.

See Also:
getLabelFont()

getLabelFont

public WFont getLabelFont()
Returns the axis label font.

See Also:
setLabelFont(WFont labelFont)

getChart

public WCartesianChart getChart()
Returns the chart to which this axis belongs.

See Also:
WCartesianChart.getAxis(Axis axis)