Class WCartesianChart


  • public class WCartesianChart
    extends WAbstractChart
    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 ChartType.Category or a ChartType.Scatter.

    In a ChartType.Category, the X series represent different categories, which are listed consecutively in model row order. The X axis scale is set to AxisScale.Discrete.

    A category chart with bar series

    Each series may be rendered differently, and this is configured in the data series (see WDataSeries for more information).

    In a ChartType.Scatter, the X series data are interpreted as numbers on a numerical scale. The scale for the X axis defaults to a AxisScale.Linear, but this may be changed to a AxisScale.Date when the X series contains dates (of type WDate) to create a time series chart, or to a AxisScale.Log. A ChartType.Scatter supports the same types of data series as a ChartType.Category, 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

    Missing data in a model series Y values is interpreted as a break. For curve-like series, this breaks the curve (or line).

    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 Orientation.Vertical orientation. The orientation may be changed to Orientation.Horizontal using setOrientation().

    The styling of the series data are dictated by a palette which may be set using setPalette(WChartPalette *), but may be overridden by settings in each data series.

    CSS

    Styling through CSS is not applicable.

    Client-side interaction

    WCartesianChart has several features that allow interaction with the chart without server roundtrips. These features include zoom, pan, crosshair and follow curve functionality.

    Note: Client side interaction is only available if the chart is drawn on an HTML canvas. This is the default rendering method on modern browsers, see WPaintedWidget#setPreferredMethod()

    Note: Some features are currently not supported in interactive mode:

    • Axes set at AxisValue.Zero position will not always be drawn correctly. They may be clipped off outside of the chart area, and when zooming, the axis ticks will change size.
    • WAxis#setBreak() is incompatible with interactive mode
    See Also:
    WDataSeries, WAxis, WPieChart
    • Method Detail

      • setXSeriesColumn

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

        Use this method to specify the default data for the X series. For a ChartType.Scatter this is mandatory if an X series is not specified for every WDataSeries. For a ChartType.Category, 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.

        See Also:
        XSeriesColumn()
      • setTextPen

        public void setTextPen​(WPen pen)
        set the pen used to render the labels

        This method overwrites the pen for all axes

        See Also:
        WAxis.setTextPen(WPen pen)
      • addSeries

        public void addSeries​(WDataSeries series)
        Adds a data 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.

        See Also:
        removeSeries(WDataSeries series), setSeries(List series)
      • getSeries

        public WDataSeries getSeries​(int modelColumn)
        Returns a data series corresponding to a data column.

        Returns a reference to the first data series that plots data from modelColumn.

      • getSeries

        public java.util.List<WDataSeries> getSeries()
        Returns a list with the current data series.

        Returns the complete list of current data series.

      • getAxis

        public WAxis getAxis​(Axis axis)
        Returns a chart axis.

        Returns a reference to the specified axis.

      • getXAxes

        public java.util.List<WAxis> getXAxes()
        Returns a vector of all X axes associated with this chart.

        This defaults to a vector of one axis.

      • getYAxes

        public java.util.List<WAxis> getYAxes()
        Returns a vector of all Y axes associated with this chart.

        This defaults to a vector of two axes: the Y1 and Y2 axes. Y1 will be at index 0, and Y2 will be at index 1.

      • getXAxisCount

        public int getXAxisCount()
        Returns the number of X axes associated with this chart.
      • getYAxisCount

        public int getYAxisCount()
        Returns the number of Y axes associated with this chart.
      • getXAxis

        public WAxis getXAxis​(int i)
        Retrieves the X axis at index i.

        The following expression is always true:

        
         getAxis(Axis.XAxis) == getXAxis(0)
        
         

        Note: Precondition: 0 <= i < getXAxisCount()

      • getYAxis

        public WAxis getYAxis​(int i)
        Retrieves the Y axis at index i.

        The following expressions are always true:

        
         axis(Y1) == yAxis(0)
         axis(Y2) == yAxis(1)
        
         

        Note: Precondition: 0 <= i < getYAxisCount()

      • addXAxis

        public int addXAxis​(WAxis waxis)
        Adds a X axis to this chart.

        The first extra axis will have index 1, the next index 2,...

        Returns the index of the added axis.

        Note: This transfers ownership of the given WAxis to this chart.

        Note: Precondition: waxis is not null

      • addYAxis

        public int addYAxis​(WAxis waxis)
        Adds a Y axis to this chart.

        The first extra axis will have index 2, the next index 3,...

        Returns the index of the added axis.

        Note: This transfers ownership of the given WAxis to this chart.

        Note: Precondition: waxis is not null

      • removeXAxis

        public WAxis removeXAxis​(int xAxisId)
        Removes the X axis with the given id.

        The indices of the axes with an id higher than xAxisId will be decremented.

        Any WDataSeries associated with the removed axis are also removed.

        Note: Precondition: 0 <= xAxisId < getXAxisCount()

      • removeYAxis

        public WAxis removeYAxis​(int yAxisId)
        Removes the Y axis with the given id.

        The indices of the axes with an id higher than yAxisId will be decremented.

        Any WDataSeries associated with the removed axis are also removed.

        Note: Precondition: 0 <= yAxisId < getYAxisCount()

      • clearXAxes

        public void clearXAxes()
        Clears all X axes.

        The effect is the same as repeatedly using removeYAxis() until are axes are removed, i.e. any WDataSeries will also be removed.

      • clearYAxes

        public void clearYAxes()
        Clears all Y axes.

        The effect is the same as repeatedly using removeYAxis() until are axes are removed, i.e. any WDataSeries will also be removed.

      • setBarMargin

        public void setBarMargin​(double margin)
        Sets the margin between bars of different series.

        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.

      • getBarMargin

        public double getBarMargin()
        Returns the margin between bars of different series.

        See Also:
        setBarMargin(double margin)
      • setLegendStyle

        public void setLegendStyle​(WFont font,
                                   WPen border,
                                   WBrush background)
        Configures the legend decoration.

        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 PenStyle::None and the default background is BrushStyle::None.

        See Also:
        setLegendEnabled(boolean enabled)
      • setLegendColumns

        public void setLegendColumns​(int columns,
                                     WLength columnWidth)
        Configures multiple legend columns.

        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.

        When automatic chart layout is enabled, then the legend column width is computed automatically, and this setting is ignored.

        See Also:
        WAbstractChart.setAutoLayoutEnabled(boolean enabled)
      • paint

        public void paint​(WPainter painter,
                          WRectF rectangle)
        Description copied from class: WAbstractChart
        Paint the chart in a rectangle of the given painter.

        Paints the chart inside the painter, in the area indicated by rectangle. When rectangle is a null rectangle, the entire painter WPainter.getWindow() is used.

        Specified by:
        paint in class WAbstractChart
      • drawMarker

        public void drawMarker​(WDataSeries series,
                               WPainterPath result)
        Draws the marker for a given data series.

        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.

        See Also:
        setLegendEnabled(boolean enabled)
      • renderLegendIcon

        public void renderLegendIcon​(WPainter painter,
                                     WPointF pos,
                                     WDataSeries series)
        Renders the legend icon for a given data 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.

        See Also:
        renderLegendItem(WPainter painter, WPointF pos, WDataSeries series)
      • renderLegendItem

        public void renderLegendItem​(WPainter painter,
                                     WPointF pos,
                                     WDataSeries series)
        Renders the legend item for a given data 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.

        See Also:
        setLegendEnabled(boolean enabled)
      • mapFromDevice

        public WPointF mapFromDevice​(WPointF point,
                                     Axis ordinateAxis)
        Maps from device coordinates to model coordinates.

        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 that the mapping already reflects model changes since the last rendering, you should call initLayout() first.

        If the chart is interactive, mapFromDevice will correctly take the current zoom range into account.

        See Also:
        mapToDevice(Object xValue, Object yValue, Axis axis, int xSegment, int ySegment)
      • mapFromDevice

        public WPointF mapFromDevice​(WPointF point,
                                     int ordinateAxis)
        Maps from device coordinates to model coordinates.

        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 that the mapping already reflects model changes since the last rendering, you should call initLayout() first.

        If the chart is interactive, mapFromDevice will correctly take the current zoom range into account.

        See Also:
        mapToDevice(Object xValue, Object yValue, Axis axis, int xSegment, int ySegment)
      • mapFromDeviceWithoutTransform

        public WPointF mapFromDeviceWithoutTransform​(WPointF point,
                                                     Axis ordinateAxis)
        Maps from device coordinates to model coordinates, ignoring the current zoom range.

        Maps a position in the chart back to model coordinates, as if the chart was not zoomed in (nor panned).

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

        This function will not take the current zoom range into account. The mapping will be performed as if zoomRangeTransform() is the identity transform.

        See Also:
        mapToDeviceWithoutTransform(Object xValue, Object yValue, Axis ordinateAxis, int xSegment, int ySegment)
      • mapFromDevice

        public WPointF mapFromDevice​(WPointF point,
                                     WAxis xAxis,
                                     WAxis yAxis)
        Maps from device coordinates to model coordinates.

        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 that the mapping already reflects model changes since the last rendering, you should call initLayout() first.

        If the chart is interactive, mapFromDevice will correctly take the current zoom range into account.

        See Also:
        mapToDevice(Object xValue, Object yValue, Axis axis, int xSegment, int ySegment)
      • mapFromDeviceWithoutTransform

        public WPointF mapFromDeviceWithoutTransform​(WPointF point,
                                                     int ordinateAxis)
        Maps from device coordinates to model coordinates, ignoring the current zoom range.

        Maps a position in the chart back to model coordinates, as if the chart was not zoomed in (nor panned).

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

        This function will not take the current zoom range into account. The mapping will be performed as if zoomRangeTransform() is the identity transform.

        See Also:
        mapToDeviceWithoutTransform(Object xValue, Object yValue, Axis ordinateAxis, int xSegment, int ySegment)
      • mapFromDeviceWithoutTransform

        public WPointF mapFromDeviceWithoutTransform​(WPointF point,
                                                     WAxis xAxis,
                                                     WAxis yAxis)
        Maps from device coordinates to model coordinates, ignoring the current zoom range.

        Maps a position in the chart back to model coordinates, as if the chart was not zoomed in (nor panned).

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

        This function will not take the current zoom range into account. The mapping will be performed as if zoomRangeTransform() is the identity transform.

        See Also:
        mapToDeviceWithoutTransform(Object xValue, Object yValue, Axis ordinateAxis, int xSegment, int ySegment)
      • mapToDevice

        public WPointF mapToDevice​(java.lang.Object xValue,
                                   java.lang.Object yValue,
                                   Axis axis,
                                   int xSegment,
                                   int ySegment)
        Maps model values onto chart coordinates.

        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 that the mapping already reflects 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).

        If the chart is interactive, mapToDevice will correctly take the current zoom range into account.

        See Also:
        mapFromDevice(WPointF point, Axis ordinateAxis)
      • mapToDevice

        public WPointF mapToDevice​(java.lang.Object xValue,
                                   java.lang.Object yValue,
                                   int axis,
                                   int xSegment,
                                   int ySegment)
        Maps model values onto chart coordinates.

        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 that the mapping already reflects 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).

        If the chart is interactive, mapToDevice will correctly take the current zoom range into account.

        See Also:
        mapFromDevice(WPointF point, Axis ordinateAxis)
      • mapToDevice

        public WPointF mapToDevice​(java.lang.Object xValue,
                                   java.lang.Object yValue,
                                   WAxis xAxis,
                                   WAxis yAxis,
                                   int xSegment,
                                   int ySegment)
        Maps model values onto chart coordinates.

        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 that the mapping already reflects 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).

        If the chart is interactive, mapToDevice will correctly take the current zoom range into account.

        See Also:
        mapFromDevice(WPointF point, Axis ordinateAxis)
      • mapToDeviceWithoutTransform

        public WPointF mapToDeviceWithoutTransform​(java.lang.Object xValue,
                                                   java.lang.Object yValue,
                                                   Axis ordinateAxis,
                                                   int xSegment,
                                                   int ySegment)
        Maps model values onto chart coordinates, ignoring the current zoom range.

        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 that the mapping already reflects 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).

        This function will not take the current zoom range into account.The mapping will be performed as if zoomRangeTransform() is the identity transform.

        See Also:
        mapFromDeviceWithoutTransform(WPointF point, Axis ordinateAxis)
      • mapToDeviceWithoutTransform

        public WPointF mapToDeviceWithoutTransform​(java.lang.Object xValue,
                                                   java.lang.Object yValue,
                                                   int ordinateAxis,
                                                   int xSegment,
                                                   int ySegment)
        Maps model values onto chart coordinates, ignoring the current zoom range.

        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 that the mapping already reflects 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).

        This function will not take the current zoom range into account.The mapping will be performed as if zoomRangeTransform() is the identity transform.

        See Also:
        mapFromDeviceWithoutTransform(WPointF point, Axis ordinateAxis)
      • mapToDeviceWithoutTransform

        public WPointF mapToDeviceWithoutTransform​(java.lang.Object xValue,
                                                   java.lang.Object yValue,
                                                   WAxis xAxis,
                                                   WAxis yAxis,
                                                   int xSegment,
                                                   int ySegment)
        Maps model values onto chart coordinates, ignoring the current zoom range.

        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 that the mapping already reflects 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).

        This function will not take the current zoom range into account.The mapping will be performed as if zoomRangeTransform() is the identity transform.

        See Also:
        mapFromDeviceWithoutTransform(WPointF point, Axis ordinateAxis)
      • initLayout

        public boolean initLayout​(WRectF rectangle,
                                  WPaintDevice device)
        Initializes the chart layout.

        The mapping between model and device coordinates is only established after a rendering phase, or after calling initLayout manually.

        You need a layout in order to use the mapFromDevice() and mapToDevice() methods.

        Unless a specific chart rectangle is specified, the entire widget area is assumed.

      • createLegendItemWidget

        public WWidget createLegendItemWidget​(int index)
        Creates a widget which renders the a legend item.

        The legend item widget will contain a text and a WPaintedWidget which draws the series' symbol.

      • addDataPointArea

        public void addDataPointArea​(WDataSeries series,
                                     int xRow,
                                     int xColumn,
                                     WAbstractArea area)
        Adds a data point area (used for displaying e.g. tooltips).

        You may want to specialize this is if you wish to modify (or ignore) the area.

        Note: Currently, an area is only created if the ItemDataRole.ToolTip data at the data point is not empty.

      • setAxisPadding

        public void setAxisPadding​(int padding)
        Sets the padding between the chart area and the axes.

        This calls WAxes::setPadding() on all axes.

        See Also:
        getAxisPadding()
      • getAxisPadding

        public int getAxisPadding()
        Returns the padding between the chart area and the axes.

        This number may not reflect the actual padding of the individual axes, if another padding has been applied on the individual axes.

        See Also:
        setAxisPadding(int padding)
      • setBorderPen

        public void setBorderPen​(WPen pen)
        Sets the pen of the border to be drawn around the chart area.

        See Also:
        getBorderPen()
      • getBorderPen

        public WPen getBorderPen()
        Returns the pen used to draw the border around the chart area.

        Defaults to PenStyle::None.

        See Also:
        setBorderPen(WPen pen)
      • setZoomEnabled

        public void setZoomEnabled​(boolean zoomEnabled)
        Enables zoom functionality.

        When using the mouse, press the ctrl key while scrolling to zoom in/out a specific point on the chart. If you press shift+ctrl, it will only zoom vertically. If you press alt+ctrl, it will only zoom horizontally. To change these default mappings, use setWheelActions().

        When using touch, you can use a pinch gesture to zoom in/out. If the pinch gesture is vertical/horizontal, it will zoom only vertically/horizontally, otherwise it will zoom both axes equally.

        The default value is false.

        See Also:
        isZoomEnabled(), setWheelActions(Map wheelActions)
      • setZoomEnabled

        public final void setZoomEnabled()
        Enables zoom functionality.

        Calls setZoomEnabled(true)

      • setPanEnabled

        public void setPanEnabled​(boolean panEnabled)
        Enables pan functionality.

        When using the mouse, you can click and drag to pan the chart (if zoomed in), or use the scrollwheel.

        When using touch, you can drag to pan the chart. If the rubberband effect is enabled, this is intertial (it will keep scrolling after you let go) and there is an overscroll and bounce back effect on the sides.

        The default value is false.

        See Also:
        isPanEnabled()
      • setPanEnabled

        public final void setPanEnabled()
        Enables pan functionality.

        Calls setPanEnabled(true)

      • setCrosshairEnabled

        public void setCrosshairEnabled​(boolean crosshair)
        Enables the crosshair functionality.

        When enabled, the crosshair will follow mouse movement, and show in the top right corner the coordinate (according to X axis and the first Y axis) corresponding to this position.

        When using touch, the crosshair can be moved with a drag. If both panning and the crosshair are enabled, the crosshair will be moved when dragging close to the crosshair. Otherwise, the chart will pan.

      • setCrosshairEnabled

        public final void setCrosshairEnabled()
        Enables the crosshair functionality.

        Calls setCrosshairEnabled(true)

      • setCrosshairXAxis

        public void setCrosshairXAxis​(int xAxis)
        Sets the X axis to use for the crosshair.

        Defaults to 0 (first X axis)

      • getCrosshairXAxis

        public int getCrosshairXAxis()
        Returns the X axis to use for the crosshair.
      • setCrosshairYAxis

        public void setCrosshairYAxis​(int yAxis)
        Sets the Y axis to use for the crosshair.

        Defaults to 0 (first Y axis)

      • getCrosshairYAxis

        public int getCrosshairYAxis()
        Returns the Y axis to use for the crosshair.
      • setFollowCurve

        public void setFollowCurve​(int followCurve)
        Deprecated.
        Use setFollowCurve() instead
        Enables the follow curve functionality for a data series.

        This enables follow curve functionality for the data series corresponding to the given column.

        If the data series is of type SeriesType.Line or SeriesType.Curve, the crosshair can only be moved in the x direction. The y position of the crosshair will be determined by the value of the data series. The crosshair will snap to the nearest point that is defined in the data series.

        When using the mouse, the x position will change on mouseover. When using touch, the x position can be moved with a drag. The follow curve functionality has priority over the crosshair functionality.

        Use column index -1 or disableFollowCurve() to disable the follow curve feature.

        Note: The follow curve functionality requires that the X axis values of the data series are monotonically increasing or decreasing.

      • setFollowCurve

        public void setFollowCurve​(WDataSeries series)
        Enabled the follow curve funtionality for a data series.

        This enables follow curve functionality for the data series corresponding to the given column.

        If the data series is of type SeriesType.Line or SeriesType.Curve, the crosshair can only be moved in the x direction. The y position of the crosshair will be determined by the value of the data series. The crosshair will snap to the nearest point that is defined in the data series.

        When using the mouse, the x position will change on mouseover. When using touch, the x position can be moved with a drag. The follow curve functionality has priority over the crosshair functionality.

        Set to null to disable the follow curve feature.

        Note: The follow curve functionality requires that the X axis values of the data series are monotonically increasing or decreasing.

      • setRubberBandEffectEnabled

        public void setRubberBandEffectEnabled​(boolean rubberBandEnabled)
        Enables/disables the inertial scrolling and rubberband effect.

        See Also:
        setPanEnabled(boolean panEnabled)
      • setRubberBandEffectEnabled

        public final void setRubberBandEffectEnabled()
        Enables/disables the inertial scrolling and rubberband effect.

        Calls setRubberBandEffectEnabled(true)

      • setSeriesSelectionEnabled

        public void setSeriesSelectionEnabled​(boolean enabled)
        Sets whether series selection is enabled.

        If series selection is enabled, series can be selected with a mouse click or long press. If the selected series is a SeriesType.Line or SeriesType.Curve, it can be manipulated if curve manipulation is enabled. The series that are not selected, will be shown in a lighter color.

      • setSeriesSelectionEnabled

        public final void setSeriesSelectionEnabled()
        Sets whether series selection is enabled.

        Calls setSeriesSelectionEnabled(true)

      • seriesSelected

        public Signal2<WDataSeries,​WPointF> seriesSelected()
        A signal that notifies the selection of a new curve.

        This signal is emitted if a series is selected using a mouse click or long press. The first argument is the selected series. The second argument is the point that was selected, in model coordinates.

        See Also:
        setSeriesSelectionEnabled(boolean enabled)
      • setOnDemandLoadingEnabled

        public void setOnDemandLoadingEnabled​(boolean enabled)
        Enable on-demand loading.

        By default, when on-demand loading is not enabled, the entire chart area is loaded, regardless of whether it is within the current zoom range of the X axis.

        When on-demand loading is enabled only the currently visible area + some margin is loaded. As the visible area changes, different data is loaded. This improves performance for charts with a lot of data if not all of the data needs to be visible at the same time.

        This feature is especially useful in combination with WAxis#setMaximumZoomRange() or WAxis#setMinZoom(), which makes it impossible for the user to view all of the data at the same time, because that would incur too much overhead.

        Note: On-demand loading requires that the X axis data for all data series is sorted in ascending order. This feature is optimized for equidistant X axis data, but that's not a requirement.

        Note: If no minimum or maximum are set on the Y axis (or axes), then the chart will still have to scan all data of its data series to automatically determine the minimum and maximum Y axis values. If this performance hit is undesirable and the Y axis range is known or guaranteed to be within a certain range, make sure to set a range on the Y axis (or axes).

        See Also:
        isOnDemandLoadingEnabled()
      • iterateSeries

        public void iterateSeries​(SeriesIterator iterator,
                                  WPainter painter,
                                  boolean reverseStacked,
                                  boolean extremesOnly)
      • iterateSeries

        public final void iterateSeries​(SeriesIterator iterator,
                                        WPainter painter,
                                        boolean reverseStacked)
      • getDomChanges

        protected void getDomChanges​(java.util.List<DomElement> result,
                                     WApplication app)
        Description copied from class: WWebWidget
        Get DOM changes for this widget.

        This is an internal function, and should not be called directly, or be overridden!

        Overrides:
        getDomChanges in class WPaintedWidget
      • render

        protected void render​(WPainter painter,
                              WRectF rectangle)
        Renders the chart.

        Renders the chart within the given rectangle. To accomodate both rendering of horizontal and vertically oriented charts, all rendering logic assumes horizontal. This "chart coordinates" space is transformed to painter coordinates using hv().

      • map

        protected WPointF map​(double xValue,
                              double yValue,
                              Axis yAxis,
                              int currentXSegment,
                              int currentYSegment)
        Map (x, y) value pair to chart coordinates coordinates.

        The result needs further transformation using hv() to painter coordinates.

      • map

        protected WPointF map​(double xValue,
                              double yValue,
                              int yAxis,
                              int currentXSegment,
                              int currentYSegment)
        Map (x, y) value pair to chart coordinates coordinates.

        The result needs further transformation using hv() to painter coordinates.

      • map

        protected WPointF map​(double xValue,
                              double yValue,
                              WAxis xAxis,
                              WAxis yAxis,
                              int currentXSegment,
                              int currentYSegment)
        Map (x, y) value pair to chart coordinates coordinates.

        The result needs further transformation using hv() to painter coordinates.

      • renderLabel

        protected void renderLabel​(WPainter painter,
                                   java.lang.CharSequence text,
                                   WPointF p,
                                   java.util.EnumSet<AlignmentFlag> flags,
                                   double angle,
                                   int margin)
        Utility function for rendering text.

        This method renders text on the chart position pos, with a particular alignment flags. These are both specified in chart coordinates. The position is converted to painter coordinates using hv(), and the alignment flags are changed accordingly. The rotation, indicated by angle is specified in painter coordinates and thus an angle of 0 always indicates horizontal text, regardless of the chart orientation.

      • hv

        protected WPointF hv​(double x,
                             double y)
        Conversion between chart and painter coordinates.

        Converts from chart coordinates to painter coordinates, taking into account the chart orientation.

      • hv

        protected WPointF hv​(WPointF p)
        Conversion between chart and painter coordinates.

        Converts from chart coordinates to painter coordinates, taking into account the chart orientation.

      • hv

        protected WRectF hv​(WRectF r)
        Conversion between chart and painter coordinates.

        Converts from chart coordinates to painter coordinates, taking into account the chart orientation.

      • chartSegmentArea

        protected WRectF chartSegmentArea​(WAxis yAxis,
                                          int xSegment,
                                          int ySegment)
        Returns the segment area for a combination of X and Y segments.

        This segment area is used for clipping when rendering in a particular segment.

      • chartSegmentArea

        protected WRectF chartSegmentArea​(WAxis xAxis,
                                          WAxis yAxis,
                                          int xSegment,
                                          int ySegment)
        Returns the segment area for a combination of X and Y segments.

        This segment area is used for clipping when rendering in a particular segment.

      • calcChartArea

        protected void calcChartArea()
        Calculates the chart area.

        This calculates the chartArea(), which is the rectangle (in chart coordinates) that bounds the actual chart (thus excluding axes, labels, titles, legend, etc...).

        See Also:
        WAbstractChart.getPlotAreaPadding(Side side)
      • prepareAxes

        protected boolean prepareAxes​(WPaintDevice device)
        Prepares the axes for rendering.

        Computes axis properties such as the range (if not manually specified), label interval (if not manually specified) and axis locations. These properties are stored within the axes.

        See Also:
        initLayout(WRectF rectangle, WPaintDevice device)
      • renderOther

        protected void renderOther​(WPainter painter)
        Renders other, user-defined things.

        The default implementation sets the painter's clip path to the chart area, but does not enable clipping.

        This method can be overridden to draw extra content onto the chart.

        Chart coordinates can be mapped to device coordinates with mapToDeviceWithoutTransform(). If these need to move and scale along with the zoom range, those points can be transformed with zoomRangeTransform().

        This method is called last by default. If you want to render other things at some other moment, you can override render(WPainter&, const WRectF&).

      • getCalcNumBarGroups

        protected int getCalcNumBarGroups()
        Calculates the total number of bar groups.
      • render

        protected void render​(java.util.EnumSet<RenderFlag> flags)
        Description copied from class: WWidget
        Renders the widget.

        This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

        The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

        Overrides:
        render in class WPaintedWidget