|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.webtoolkit.jwt.WObject
eu.webtoolkit.jwt.WWidget
eu.webtoolkit.jwt.WWebWidget
eu.webtoolkit.jwt.WInteractWidget
eu.webtoolkit.jwt.WPaintedWidget
eu.webtoolkit.jwt.chart.WAbstractChart
eu.webtoolkit.jwt.chart.WCartesianChart
public class WCartesianChart
A cartesian chart.
A cartesian chart is a chart that uses X and Y axes. It can display one or multiple data series, which each may be rendered using bars, lines, areas, or points.
To use a cartesian chart, the minimum you need to do is set a model using
WAbstractChart#setModel(), set the model column that holds the X data using
setXSeriesColumn(),
and add one or more series using
addSeries(). Each
series corresponds to one data column that holds Y data.
A cartesian chart is either a CategoryChart
or a ScatterPlot.
In a CategoryChart, the X series represent different categories, which
are listed consecutively in model row order. The X axis scale is set to
CategoryScale.
A category chart with bar series
WDataSeries for more information).
In a ScatterPlot, the X series data are interpreted as numbers on a
numerical scale. The scale for the X axis defaults to a
LinearScale, but this may be changed to a
DateScale when the X series contains dates (of
type WDate) to create a time series chart, or to a
LogScale. A ScatterPlot supports the same types of
data series as a CategoryChart, but does not support stacking. In a scatter
plot, the X series do not need to be ordered in increasing values, and may be
set differently for each dataseries using
WDataSeries#setXSeriesColumn().
A time series scatter plot with line series
The cartesian chart has support for dual Y axes. Each data series may be bound to one of the two Y axes. By default, only the first Y axis is displayed. To show the second Y axis you will need to call:
By default a chart has a horizontal X axis and a vertical Y axis, which
corresponds to a Vertical orientation. The
orientation may be changed to Horizontal using
setOrientation().
The styling of the series data are dictated by a palette which may be set
using WAbstractChart#setPalette(), but may be overridden by settings in each data
series.
Styling through CSS is not applicable.
WDataSeries,
WAxis,
WPieChart| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WPaintedWidget |
|---|
WPaintedWidget.Method |
| Constructor Summary | |
|---|---|
WCartesianChart()
Creates a new cartesian chart. |
|
WCartesianChart(ChartType type)
Creates a new cartesian chart. |
|
WCartesianChart(ChartType type,
WContainerWidget parent)
Creates a new cartesian chart. |
|
WCartesianChart(WContainerWidget parent)
Creates a new cartesian chart. |
|
| Method Summary | |
|---|---|
void |
addDataPointArea(WDataSeries series,
WModelIndex xIndex,
WAbstractArea area)
Adds a data point area (used for displaying e.g. |
void |
addSeries(WDataSeries series)
Adds a data series. |
WWidget |
createLegendItemWidget(int index)
Creates a widget which renders the a legend item. |
protected WChart2DRenderer |
createRenderer(WPainter painter,
WRectF rectangle)
Creates a renderer which renders the chart. |
void |
drawMarker(WDataSeries series,
WPainterPath result)
Draws the marker for a given data series. |
WAxis |
getAxis(Axis axis)
Returns a chart axis. |
double |
getBarMargin()
Returns the margin between bars of different series. |
AlignmentFlag |
getLegendAlignment()
Returns the legend alignment. |
WBrush |
getLegendBackground()
Returns the legend background brush. |
WPen |
getLegendBorder()
Returns the legend border pen. |
int |
getLegendColumns()
Returns the legend columns. |
WLength |
getLegendColumnWidth()
Returns the legend column width. |
WFont |
getLegendFont()
Returns the legend font. |
LegendLocation |
getLegendLocation()
Returns the legend location. |
Side |
getLegendSide()
Returns the legend side. |
Orientation |
getOrientation()
Returns the chart orientation. |
java.util.List<WDataSeries> |
getSeries()
Returns a list with the current data series. |
WDataSeries |
getSeries(int modelColumn)
Returns a data series corresponding to a data column. |
ChartType |
getType()
Returns the chart type. |
void |
initLayout()
Initializes the chart layout. |
void |
initLayout(WRectF rectangle)
Initializes the chart layout. |
boolean |
isLegendEnabled()
Returns whether the legend is enabled. |
WPointF |
mapFromDevice(WPointF point)
Maps from device coordinates to model coordinates. |
WPointF |
mapFromDevice(WPointF point,
Axis ordinateAxis)
Maps from device coordinates to model coordinates. |
WPointF |
mapToDevice(java.lang.Object xValue,
java.lang.Object yValue)
Maps model values onto chart coordinates. |
WPointF |
mapToDevice(java.lang.Object xValue,
java.lang.Object yValue,
Axis ordinateAxis)
Maps model values onto chart coordinates. |
WPointF |
mapToDevice(java.lang.Object xValue,
java.lang.Object yValue,
Axis ordinateAxis,
int xSegment)
Maps model values onto chart coordinates. |
WPointF |
mapToDevice(java.lang.Object xValue,
java.lang.Object yValue,
Axis ordinateAxis,
int xSegment,
int ySegment)
Maps model values onto chart coordinates. |
protected void |
modelChanged()
Method called whenever the entire model was changed. |
protected void |
modelColumnsInserted(WModelIndex parent,
int start,
int end)
Method called when colums have been inserted in the model. |
protected void |
modelColumnsRemoved(WModelIndex parent,
int start,
int end)
Method called when colums have been removed from the model. |
protected void |
modelDataChanged(WModelIndex topLeft,
WModelIndex bottomRight)
Method called when data has been changed in the model. |
protected void |
modelReset()
Method called whenever the entire model was reset. |
protected void |
modelRowsInserted(WModelIndex parent,
int start,
int end)
Method called when rows have been inserted from the model. |
protected void |
modelRowsRemoved(WModelIndex parent,
int start,
int end)
Method called when rows have been removed from the model. |
void |
paint(WPainter painter,
WRectF rectangle)
Paint the chart in a rectangle of the given painter. |
protected void |
paintEvent(WPaintDevice paintDevice)
Paints the widget. |
void |
removeSeries(int modelColumn)
Removes a data series. |
void |
renderLegendIcon(WPainter painter,
WPointF pos,
WDataSeries series)
Renders the legend icon for a given data series. |
void |
renderLegendItem(WPainter painter,
WPointF pos,
WDataSeries series)
Renders the legend item for a given data series. |
void |
setBarMargin(double margin)
Sets the margin between bars of different series. |
void |
setLegendColumns(int columns,
WLength columnWidth)
Configures multiple legend columns. |
void |
setLegendEnabled(boolean enabled)
Enables the legend. |
void |
setLegendLocation(LegendLocation location,
Side side,
AlignmentFlag alignment)
Configures the legend location. |
void |
setLegendStyle(WFont font,
WPen border,
WBrush background)
Configures the legend decoration. |
void |
setOrientation(Orientation orientation)
Sets the chart orientation. |
void |
setSeries(java.util.List<WDataSeries> series)
Sets all data series. |
void |
setType(ChartType type)
Sets the chart type. |
void |
setXSeriesColumn(int modelColumn)
Sets the the model column for the X series. |
int |
XSeriesColumn()
Returns the model column for the X series. |
| Methods inherited from class eu.webtoolkit.jwt.chart.WAbstractChart |
|---|
getBackground, getModel, getPalette, getPlotAreaPadding, getTitle, getTitleFont, paint, remove, setBackground, setModel, setPalette, setPlotAreaPadding, setPlotAreaPadding, setPlotAreaPadding, setTitle, setTitleFont |
| Methods inherited from class eu.webtoolkit.jwt.WPaintedWidget |
|---|
addArea, enableAjax, getArea, getAreas, getMethod, getPreferredMethod, insertArea, layoutSizeChanged, removeArea, resize, setPreferredMethod, update, update, update |
| Methods inherited from class eu.webtoolkit.jwt.WInteractWidget |
|---|
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, touchEnded, touchMoved, touchStarted |
| Methods inherited from class eu.webtoolkit.jwt.WWidget |
|---|
acceptDrops, acceptDrops, addCssRule, addCssRule, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, containsExposed, disable, dropEvent, enable, getDrop, getJsRef, getParent, hide, htmlText, isLayoutSizeAware, positionAt, positionAt, removeStyleClass, resize, setClearSides, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr |
| Methods inherited from class eu.webtoolkit.jwt.WObject |
|---|
addChild, getObjectName, setObjectName |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WCartesianChart(WContainerWidget parent)
Creates a cartesian chart of type CategoryChart.
public WCartesianChart()
Calls this((WContainerWidget)null)
public WCartesianChart(ChartType type,
WContainerWidget parent)
Creates a cartesian chart of the indicated type.
public WCartesianChart(ChartType type)
Calls this(type, (WContainerWidget)null)
| Method Detail |
|---|
public void setType(ChartType type)
The chart type determines how (x,y) data are interpreted. In a
CategoryChart, the X values are
categories, and these are plotted consecutively, evenly spaced, and in
row order. In a ScatterPlot, the X values
are interpreted numerically (as for Y values).
The default chart type is a CategoryChart.
getType(),
WAxis.setScale(AxisScale scale),
getAxis(Axis axis)public ChartType getType()
setType(ChartType type)public void setOrientation(Orientation orientation)
Sets the chart orientation, which corresponds to the orientation of the Y
axis: a Orientation.Vertical orientation corresponds to the
conventional way of a horizontal X axis and vertical Y axis. A
Orientation.Horizontal orientation is the other way around.
The default orientation is Orientation.Vertical.
getOrientation()public Orientation getOrientation()
setOrientation(Orientation orientation)public void setXSeriesColumn(int modelColumn)
Use this method to specify the data for the X series. For a
ScatterPlot this is mandatory, while for a
CategoryChart, if not specified, an
increasing series of integer numbers will be used (1, 2, ...).
Scatterplot dataseries may each individually be given its own X series
data using WDataSeries#setXSeriesColumn()
The default value is -1 (not specified).
The series column is reset to -1 when the model is set (or changed). Thus you need to set a model before configuring the series.
XSeriesColumn()public int XSeriesColumn()
setXSeriesColumn(int modelColumn)public void addSeries(WDataSeries series)
A single chart may display one or more data series. Each data series displays data from a single model column in the chart. Series are plotted in the order that they have been added to the chart.
The series column is reset to -1 when the model is set (or changed). Thus you need to set a model before configuring the series.
removeSeries(int modelColumn),
setSeries(List series)public void removeSeries(int modelColumn)
This removes the first data series which plots the given
modelColumn.
addSeries(WDataSeries series),
setSeries(List series)public void setSeries(java.util.List<WDataSeries> series)
Replaces the current list of series with the new list.
getSeries(int modelColumn),
addSeries(WDataSeries series),
removeSeries(int modelColumn)public WDataSeries getSeries(int modelColumn)
Returns a reference to the first data series that plots data from
modelColumn.
public java.util.List<WDataSeries> getSeries()
Returns the complete list of current data series.
setSeries(List series)public WAxis getAxis(Axis axis)
Returns a reference to the specified axis.
public void setBarMargin(double margin)
Use this method to change the margin that is set between bars of different series. The margin is specified as a fraction of the width. For example, a value of 0.1 adds a 10% margin between bars of each series. Negative values are also allowed. For example, use a margin of -1 to plot the bars of different series on top of each other.
The default value is 0.
public double getBarMargin()
setBarMargin(double margin)public void setLegendEnabled(boolean enabled)
The location of the legend can be configured using
setLegendLocation(). Only series for which the legend is enabled or
included in this legend.
The default value is false.
WDataSeries.isLegendEnabled(),
setLegendLocation(LegendLocation location, Side
side, AlignmentFlag alignment)public boolean isLegendEnabled()
setLegendEnabled(boolean enabled)
public void setLegendLocation(LegendLocation location,
Side side,
AlignmentFlag alignment)
The legend can be renderd either inside or outside of the chart area.
When location is Chart::LegendInside, the legend will be rendered inside the chart. When
location is Chart::Legendoutside, the legend is rendered outside the chart, in the
chart padding area.
The provided side can either be Side.Left,
Side.Right, Side.Top, Side.Bottom and configures
the side of the chart at which the legend is displayed.
The alignment specifies how the legend is aligned. This can
be a horizontal alignment flag (AlignmentFlag.AlignLeft,
AlignmentFlag.AlignCenter, or AlignmentFlag.AlignRight),
when the side is Bottom or Top, or a vertical alignment flag
(AlignmentFlag.AlignTop, AlignmentFlag.AlignMiddle, or
AlignmentFlag.AlignBottom) when the side is Left or
Right.
The default location is Chart::LegendOutside, Side.Right and
AlignmentFlag.AlignMiddle.
To have more control over the legend, you could reimplement the
renderLegendItem() method to customize how one item in the legend is
rendered, or, alternatively you can disable the legend generated by the
chart itself, and reimplement the
paint()
method in which you use the
renderLegendItem() method repeatedly to render a customized legend.
WDataSeries.setLegendEnabled(boolean enabled)
public void setLegendStyle(WFont font,
WPen border,
WBrush background)
This configures the font, border and background for the legend.
The default font is a 10pt sans serif font (the same as the default axis
label font), the default border is NoPen and the default background is
NoBrush.
setLegendEnabled(boolean enabled)public LegendLocation getLegendLocation()
setLegendLocation(LegendLocation location, Side
side, AlignmentFlag alignment)public Side getLegendSide()
setLegendLocation(LegendLocation location, Side
side, AlignmentFlag alignment)public AlignmentFlag getLegendAlignment()
setLegendLocation(LegendLocation location, Side
side, AlignmentFlag alignment)public int getLegendColumns()
setLegendColumns(int columns, WLength columnWidth)public WLength getLegendColumnWidth()
setLegendColumns(int columns, WLength columnWidth)public WFont getLegendFont()
setLegendStyle(WFont font, WPen border, WBrush
background)public WPen getLegendBorder()
setLegendStyle(WFont font, WPen border, WBrush
background)public WBrush getLegendBackground()
setLegendStyle(WFont font, WPen border, WBrush
background)
public void setLegendColumns(int columns,
WLength columnWidth)
Multiple columns are typically useful when placing the legend at the top or at the bottom of the chart.
The default value is a single column, 100 pixels wide.
public void paint(WPainter painter,
WRectF rectangle)
WAbstractChart
Paints the chart inside the painter, in the area indicated by
rectangle. When rectangle is a null rectangle, the entire
painter window is used.
paint in class WAbstractChart
public void drawMarker(WDataSeries series,
WPainterPath result)
Draws the marker for the indicated series in the
result. This method is called while painting the chart, and
you may want to reimplement this method if you wish to provide a custom
marker for a particular data series.
setLegendEnabled(boolean enabled)
public void renderLegendIcon(WPainter painter,
WPointF pos,
WDataSeries series)
Renders the legend icon for the indicated series in the
painter at position pos.
This method is called while rendering a legend item, and you may want to reimplement this method if you wish to provide a custom legend icon for a particular data series.
renderLegendItem(WPainter painter, WPointF pos,
WDataSeries series)
public void renderLegendItem(WPainter painter,
WPointF pos,
WDataSeries series)
Renders the legend item for the indicated series in the
painter at position pos. The default
implementation draws the marker, and the series description to the right.
The series description is taken from the model's header data for
that series' data column.
This method is called while painting the chart, and you may want to reimplement this method if you wish to provide a custom marker for a particular data series.
setLegendEnabled(boolean enabled)
public WPointF mapFromDevice(WPointF point,
Axis ordinateAxis)
Maps a position in the chart back to model coordinates.
This 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
initLayout() first.
mapToDevice(Object xValue, Object yValue, Axis
ordinateAxis, int xSegment, int ySegment)public final WPointF mapFromDevice(WPointF point)
Returns mapFromDevice(point, Axis.OrdinateAxis)
public WPointF mapToDevice(java.lang.Object xValue,
java.lang.Object yValue,
Axis ordinateAxis,
int xSegment,
int ySegment)
This returns the chart device coordinates for a (x,y) pair of model values.
This 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
initLayout() first.
The xSegment and ySegment arguments are
relevant only when the corresponding axis is broken using
WAxis#setBreak().
Then, its possible values may be 0 (below the break) or 1 (above the
break).
mapFromDevice(WPointF point, Axis ordinateAxis)
public final WPointF mapToDevice(java.lang.Object xValue,
java.lang.Object yValue)
Returns
mapToDevice(xValue, yValue, Axis.OrdinateAxis, 0, 0)
public final WPointF mapToDevice(java.lang.Object xValue,
java.lang.Object yValue,
Axis ordinateAxis)
Returns
mapToDevice(xValue, yValue, ordinateAxis, 0, 0)
public final WPointF mapToDevice(java.lang.Object xValue,
java.lang.Object yValue,
Axis ordinateAxis,
int xSegment)
Returns
mapToDevice(xValue, yValue, ordinateAxis, xSegment, 0)
public void initLayout(WRectF rectangle)
A cartesian chart delegates the rendering and layout of the chart and its
axes to a WChart2DRenderer. As a consequence, the mapping between
model and device coordinates is also established by this class, which is
only created on-demand when painging.
If you wish to establish the layout, in order to use the
mapFromDevice() and
mapToDevice() methods before the chart has been rendered, you should
call this method.
Unless a specific chart rectangle is specified, the entire widget area is assumed.
public final void initLayout()
Calls initLayout(new WRectF())
public WWidget createLegendItemWidget(int index)
The legend item widget will contain a text and a WPaintedWidget
which draws the series' symbol.
public void addDataPointArea(WDataSeries series,
WModelIndex xIndex,
WAbstractArea area)
You may want to specialize this is if you wish to modify (or delete) the area.
Note: Currently, an area is only created if the
ItemDataRole.ToolTipRole data at the data point is not empty.
protected void paintEvent(WPaintDevice paintDevice)
WPaintedWidgetYou should reimplement this method to paint the contents of the widget, using the given paintDevice.
paintEvent in class WPaintedWidget
protected WChart2DRenderer createRenderer(WPainter painter,
WRectF rectangle)
The rendering of the chart is delegated to a WChart2DRenderer
class, which will render the chart within the rectangle of
the painter.
You may want to reimplement this method if you wish to override one or
more aspects of the rendering, by returning an new instance of a
specialized WChart2DRenderer class.
After rendering, the renderer is deleted.
WChart2DRenderer.render()
protected void modelColumnsInserted(WModelIndex parent,
int start,
int end)
WAbstractChart
modelColumnsInserted in class WAbstractChartWAbstractItemModel.columnsInserted()
protected void modelColumnsRemoved(WModelIndex parent,
int start,
int end)
WAbstractChart
modelColumnsRemoved in class WAbstractChartWAbstractItemModel.columnsRemoved()
protected void modelRowsInserted(WModelIndex parent,
int start,
int end)
WAbstractChart
modelRowsInserted in class WAbstractChartWAbstractItemModel.rowsInserted()
protected void modelRowsRemoved(WModelIndex parent,
int start,
int end)
WAbstractChart
modelRowsRemoved in class WAbstractChartWAbstractItemModel.rowsRemoved()
protected void modelDataChanged(WModelIndex topLeft,
WModelIndex bottomRight)
WAbstractChart
modelDataChanged in class WAbstractChartWAbstractItemModel.dataChanged()protected void modelChanged()
WAbstractChart
modelChanged in class WAbstractChartWAbstractChart.setModel(WAbstractItemModel model)protected void modelReset()
WAbstractChart
Bound to the WAbstractItemModel#modelReset() and
WAbstractItemModel#layoutChanged() signals.
modelReset in class WAbstractChart
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||