eu.webtoolkit.jwt.chart
Class WDataSeries

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

public class WDataSeries
extends java.lang.Object

A single data series in a cartesian chart.

This class configures all aspects for rendering a single data series in a cartesian chart. A data series renders Y data from a single model column against the X series configured for the chart.

The data column should contain data that can be converted to a number, but should not necessarily be of a number type, see also StringUtils.asNumber(Object).

Multiple series of different types may be combined on a single chart.

Different styles of data series

Different styles of data series

For a category chart, series may be stacked on top of each other. This is controlled by setStacked() for a series, which if enabled, will stack that series on top of the preceding data series. This works regardless of whether they are of the same type, but obviously works visually best if these series are of the same type. When not stacked, bar series are rendered next to each other. The margin between bars of different data series is controlled using WCartesianChart#setBarMargin().

The line and color type are by default based on the chart palette, but may be overridden for a series using setPen(), setBrush(), etc...

See Also:
WCartesianChart.addSeries(WDataSeries series)

Nested Class Summary
static class WDataSeries.CustomFlag
          Enumeration that indicates an aspect of the look.
 
Constructor Summary
WDataSeries(int modelColumn)
          Constructs a new data series.
WDataSeries(int modelColumn, SeriesType type)
          Constructs a new data series.
WDataSeries(int modelColumn, SeriesType type, Axis axis)
          Constructs a new data series.
 
Method Summary
 void bindToAxis(Axis axis)
          Binds this series to a chart axis.
 Axis getAxis()
          Returns the chart axis used for this series.
 double getBarWidth()
          Returns the bar width.
 WBrush getBrush()
          Returns the brush used for filling areas for this series.
 java.util.EnumSet<WDataSeries.CustomFlag> getCustomFlags()
          Returns which aspects of the look are overriden.
 FillRangeType getFillRange()
          Returns the fill range for line or curve series.
 WColor getLabelColor()
          Returns the label color.
 MarkerType getMarker()
          Returns the data point marker.
 WBrush getMarkerBrush()
          Returns the marker brush.
 WPen getMarkerPen()
          Returns the marker pen.
 double getMarkerSize()
          Returns the marker size.
 int getModelColumn()
          Returns the model column.
 WPen getPen()
          Returns the pen used for drawing lines for this series.
 WShadow getShadow()
          Returns the shadow used for stroking lines for this series.
 SeriesType getType()
          Returns the series type.
 boolean isHidden()
          Return whether the series is hidden.
 boolean isLabelsEnabled(Axis axis)
          Returns whether labels are enabled for the given axis.
 boolean isLegendEnabled()
          Returns whether this series has an entry in the legend.
 boolean isStacked()
          Returns whether this series is stacked on top of the preceding series.
 WPointF mapFromDevice(WPointF deviceCoordinates)
          Maps from device coordinates to model coordinates.
 WPointF mapToDevice(java.lang.Object xValue, java.lang.Object yValue)
          Maps from model values to device coordinates.
 WPointF mapToDevice(java.lang.Object xValue, java.lang.Object yValue, int segment)
          Maps from model values to device coordinates.
 void setBarWidth(double width)
          Sets the bar width.
 void setBrush(WBrush brush)
          Overrides the brush used for filling areas for this series.
 void setCustomFlags(java.util.EnumSet<WDataSeries.CustomFlag> flags)
          Sets which aspects of the look are overriden.
 void setCustomFlags(WDataSeries.CustomFlag flag, WDataSeries.CustomFlag... flags)
          Sets which aspects of the look are overriden.
 void setFillRange(FillRangeType fillRange)
          Sets the fill range for line or curve series.
 void setHidden(boolean hidden)
          Hide/unhide this series.
 void setLabelColor(WColor color)
          Sets the label color.
 void setLabelsEnabled(Axis axis)
          Enables a label that is shown at the series data points.
 void setLabelsEnabled(Axis axis, boolean enabled)
          Enables a label that is shown at the series data points.
 void setLegendEnabled(boolean enabled)
          Enables the entry for this series in the legend.
 void setMarker(MarkerType marker)
          Sets the data point marker.
 void setMarkerBrush(WBrush brush)
          Sets the marker brush.
 void setMarkerPen(WPen pen)
          Sets the marker pen.
 void setMarkerSize(double size)
          Sets the marker size.
 void setModelColumn(int modelColumn)
          Sets the model column.
 void setPen(WPen pen)
          Overrides the pen used for drawing lines for this series.
 void setShadow(WShadow shadow)
          Sets a shadow used for stroking lines for this series.
 void setStacked(boolean stacked)
          Sets whether this series is stacked on top of the preceding series.
 void setType(SeriesType type)
          Sets the series type.
 void setXSeriesColumn(int modelColumn)
          Sets the X series column.
 int XSeriesColumn()
          Returns the X series column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WDataSeries

public WDataSeries(int modelColumn,
                   SeriesType type,
                   Axis axis)
Constructs a new data series.

Creates a new data series which plots the Y values from the model column modelColumn, with the indicated seriesType. The Y values are mapped to the indicated axis, which should correspond to one of the two Y axes.

See Also:
WCartesianChart.addSeries(WDataSeries series)

WDataSeries

public WDataSeries(int modelColumn)
Constructs a new data series.

Calls this(modelColumn, SeriesType.PointSeries, Axis.Y1Axis)


WDataSeries

public WDataSeries(int modelColumn,
                   SeriesType type)
Constructs a new data series.

Calls this(modelColumn, type, Axis.Y1Axis)

Method Detail

setBarWidth

public void setBarWidth(double width)
Sets the bar width.

The bar width specifies the bar width (in axis dimensions). For category plots, which may have several bars for different series next to each other, you will want to specify the same bar width for each series.

For scatter plots, you may want to set the bar width to a natural size. E.g. if you are plotting weekly measurements, you could set the width to correspond to a week (=7).

The default value is 0.8 (which leaves a 20% margin between bars for different categories in a category chart.

See Also:
WCartesianChart.setBarMargin(double margin)

getBarWidth

public double getBarWidth()
Returns the bar width.

See Also:
setBarWidth(double width)

setType

public void setType(SeriesType type)
Sets the series type.

The series type specifies how the data is plotted, i.e. using mere point markers, lines, curves, or bars.


getType

public SeriesType getType()
Returns the series type.

See Also:
setType(SeriesType type)

setModelColumn

public void setModelColumn(int modelColumn)
Sets the model column.

This specifies the model column from which the Y data is retrieved that is plotted by this series.

The data column should contain data that can be converted to a number (but should not necessarily be of a number type).

See also StringUtils.asNumber(Object).


getModelColumn

public int getModelColumn()
Returns the model column.

See Also:
setModelColumn(int modelColumn)

setXSeriesColumn

public void setXSeriesColumn(int modelColumn)
Sets the X series column.

By default, the data series uses the X series column configured for the chart. For a scatter plot, each series can have its own matching X data, which is configured here. For other plots, this setting is ignored.

The default value is -1, which indicates that WCartesianChart#XSeriesColumn() is to be used.

See Also:
WCartesianChart.setXSeriesColumn(int modelColumn)

XSeriesColumn

public int XSeriesColumn()
Returns the X series column.

See Also:
setXSeriesColumn(int modelColumn)

setStacked

public void setStacked(boolean stacked)
Sets whether this series is stacked on top of the preceding series.

For category charts, data from different series may be rendered stacked on top of each other. The rendered value is the sum of the value of this series plus the rendered value of the preceding series. For line series, you probably will want to add filling under the curve. A stacked bar series is rendered by a bar on top of the preceding bar series.

The default value is false.


isStacked

public boolean isStacked()
Returns whether this series is stacked on top of the preceding series.

See Also:
setStacked(boolean stacked)

bindToAxis

public void bindToAxis(Axis axis)
Binds this series to a chart axis.

A data series may be bound to either the first or second Y axis. Note that the second Y axis is by default not displayed.

The default value is the first Y axis.

See Also:
WAxis.setVisible(boolean visible)

getAxis

public Axis getAxis()
Returns the chart axis used for this series.

See Also:
bindToAxis(Axis axis)

setCustomFlags

public void setCustomFlags(java.util.EnumSet<WDataSeries.CustomFlag> flags)
Sets which aspects of the look are overriden.

Set which aspects of the look, that are by default based on the chart palette, are overridden by custom settings.

The default value is 0 (nothing overridden).


setCustomFlags

public final void setCustomFlags(WDataSeries.CustomFlag flag,
                                 WDataSeries.CustomFlag... flags)
Sets which aspects of the look are overriden.

Calls setCustomFlags(EnumSet.of(flag, flags))


getCustomFlags

public java.util.EnumSet<WDataSeries.CustomFlag> getCustomFlags()
Returns which aspects of the look are overriden.

See Also:
setCustomFlags(EnumSet flags)

setPen

public void setPen(WPen pen)
Overrides the pen used for drawing lines for this series.

Overrides the pen that is used to draw this series. Calling this method automatically adds CustomPen to the custom flags.

The default value is a default WPen().

See Also:
WChartPalette.getStrokePen(int index), WChartPalette.getBorderPen(int index)

getPen

public WPen getPen()
Returns the pen used for drawing lines for this series.

See Also:
setPen(WPen pen)

setBrush

public void setBrush(WBrush brush)
Overrides the brush used for filling areas for this series.

Overrides the brush that is used to draw this series which is otherwise provided by the chart palette. For a bar plot, this is the brush used to fill the bars. For a line chart, this is the brush used to fill the area under (or above) the line. Calling this method automatically adds CustomBrush to the custom flags.

See Also:
WChartPalette.getBrush(int index)

getBrush

public WBrush getBrush()
Returns the brush used for filling areas for this series.

See Also:
setBrush(WBrush brush)

setShadow

public void setShadow(WShadow shadow)
Sets a shadow used for stroking lines for this series.


getShadow

public WShadow getShadow()
Returns the shadow used for stroking lines for this series.

See Also:
setShadow(WShadow shadow)

setFillRange

public void setFillRange(FillRangeType fillRange)
Sets the fill range for line or curve series.

Line or curve series may be filled under or above the curve, using the getBrush(). This setting specifies the range that is filled. Bar series may use MinimumValueFill to configure the chart to render its bars from the data point to the bottom of the chart or MaximumValueFill to render the bars from the data point to the top of the chart. The default value is ZeroValueFill, this value configures the chart to render the bars from the data point to zero.


getFillRange

public FillRangeType getFillRange()
Returns the fill range for line or curve series.

See Also:
setFillRange(FillRangeType fillRange)

setMarker

public void setMarker(MarkerType marker)
Sets the data point marker.

Specifies a marker that is displayed at the (X,Y) coordinate for each series data point.

The default value is a CircleMarker for a PointSeries, or NoMarker otherwise.

See Also:
setMarkerPen(WPen pen), setMarkerBrush(WBrush brush)

getMarker

public MarkerType getMarker()
Returns the data point marker.

See Also:
setMarker(MarkerType marker)

setMarkerSize

public void setMarkerSize(double size)
Sets the marker size.

The default marker size is 6 pixels.


getMarkerSize

public double getMarkerSize()
Returns the marker size.

See Also:
setMarkerSize(double size)

setMarkerPen

public void setMarkerPen(WPen pen)
Sets the marker pen.

Overrides the pen used for stroking the marker. By default the marker pen is the same as getPen(). Calling this method automatically adds CustomMarkerPen to the custom flags.

See Also:
setPen(WPen pen), setMarkerBrush(WBrush brush)

getMarkerPen

public WPen getMarkerPen()
Returns the marker pen.

See Also:
setMarkerPen(WPen pen)

setMarkerBrush

public void setMarkerBrush(WBrush brush)
Sets the marker brush.

Overrides the brush used for filling the marker. By default the marker brush is the same as getBrush(). Calling this method automatically adds CustomMarkerBrush to the custom flags.

See Also:
setBrush(WBrush brush), setMarkerPen(WPen pen)

getMarkerBrush

public WBrush getMarkerBrush()
Returns the marker brush.

See Also:
setMarkerBrush(WBrush brush)

setLegendEnabled

public void setLegendEnabled(boolean enabled)
Enables the entry for this series in the legend.

When enabled, this series is added to the chart legend.

The default value is true.

See Also:
WCartesianChart.setLegendEnabled(boolean enabled)

isLegendEnabled

public boolean isLegendEnabled()
Returns whether this series has an entry in the legend.

See Also:
setLegendEnabled(boolean enabled)

setLabelsEnabled

public void setLabelsEnabled(Axis axis,
                             boolean enabled)
Enables a label that is shown at the series data points.

You may enable labels for the XAxis, YAxis or both axes. The label that is displayed is the corresponding value on that axis. If both labels are enabled then they are combined in a single text using the format: "<x-value>: <y-value>".

The default values are false for both axes (no labels).

See Also:
isLabelsEnabled(Axis axis)

setLabelsEnabled

public final void setLabelsEnabled(Axis axis)
Enables a label that is shown at the series data points.

Calls setLabelsEnabled(axis, true)


isLabelsEnabled

public boolean isLabelsEnabled(Axis axis)
Returns whether labels are enabled for the given axis.

See Also:
setLabelsEnabled(Axis axis, boolean enabled)

setLabelColor

public void setLabelColor(WColor color)
Sets the label color.

Specify the color used for the rendering labels at the data points.

See Also:
setLabelsEnabled(Axis axis, boolean enabled)

getLabelColor

public WColor getLabelColor()
Returns the label color.

See Also:
setLabelColor(WColor color)

setHidden

public void setHidden(boolean hidden)
Hide/unhide this series.

A hidden series will not be show in the chart and legend.


isHidden

public boolean isHidden()
Return whether the series is hidden.

See Also:
setHidden(boolean hidden)

mapFromDevice

public WPointF mapFromDevice(WPointF deviceCoordinates)
Maps from device coordinates to model coordinates.

Maps a position in the chart back to model coordinates, for data in this data series.

This uses WChart::mapFromDevice() passing the getAxis() to which this series is bound.

This method uses the axis dimensions that are based on the latest chart rendering. If you have not yet rendered the chart, or wish to already the mapping reflect model changes since the last rendering, you should call WCartesianChart#initLayout() first.

See Also:
mapToDevice(Object xValue, Object yValue, int segment)

mapToDevice

public WPointF mapToDevice(java.lang.Object xValue,
                           java.lang.Object yValue,
                           int segment)
Maps from model values to device coordinates.

Maps model values to device coordinates, for data in this data series.

This uses WChart::mapToDevice() passing the getAxis() to which this series is bound.

This method uses the axis dimensions that are based on the latest chart rendering. If you have not yet rendered the chart, or wish to already the mapping reflect model changes since the last rendering, you should call WCartesianChart#initLayout() first.

See Also:
mapFromDevice(WPointF deviceCoordinates)

mapToDevice

public final WPointF mapToDevice(java.lang.Object xValue,
                                 java.lang.Object yValue)
Maps from model values to device coordinates.

Returns mapToDevice(xValue, yValue, 0)