Skip to main content
Version: 6.1

Area chart

(quoted from Area chart definition in Wikipedia)

A area chart displays graphically quantitative data. It is based on the area chart. The area between axis and area are commonly emphasized with colors, textures and hatchings. Commonly one compares two or more quantities with an area chart.

Programmatically, you could use a area chart as following:

// creates the chart    
AreaChart chart = new AreaChart();
// adds to DOM
component.add(chart);
...
// example for Elemental2
// gets the chart instance as DOM element
Element element = chart.getChartElement().as();
// adds to DOM
DomGlobal.document.body.appendChild(element);

By UIBinder (ONLY for GWT), you could use a area chart as following:

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:c="urn:import:org.pepstock.charba.client.gwt.widgets">

<g:HTMLPanel width="100%">
....
<c:AreaChartWidget ui:field="chart"/>
...
</g:HTMLPanel>
</ui:UiBinder>

Dataset

The area chart allows to define the data and a number of properties, used to display the data, by a area dataset.

Every chart has got a method to create a typed dataset accordingly with the chart type. The dataset can be also created instantiating the constructor.

// creates the chart
AreaChart chart = new AreaChart();
// creates the dataset
AreaDataset dataset = chart.newDataset();
// sets the option
dataset.setBackgroundColor(HtmlColor.RED);
...
// creates the dataset
AreaDataset datasetNew = new AreaDataset();
// sets the option
datasetNew.setBackgroundColor(HtmlColor.RED);
...
// sets the datasets to the chart
chart.getData().setDatasets(dataset, datasetNew);

The following are the attributes that you can set:

NameTypeScriptableDescription
backgroundColorString - IsColor - Pattern - GradientYesThe fill color/pattern under the area.
borderCapStyleCapStyleYesCap style of the area. See MDN.
borderColorString - IsColor - GradientYesThe color of the area.
borderDashint[]YesLength and spacing of dashes. See MDN.
borderDashOffsetdoubleYesOffset for area dashes. See MDN.
borderJoinStyleJoinStyleYesArea joint style. See MDN.
borderWidthintYesThe width of the area in pixels.
cubicInterpolationModeCubicInterpolationModeYesAlgorithm used to interpolate a smooth curve from the discrete data points.
clipboolean - double - Clip-How to clip relative to chart area. Positive value allows overflow, negative value clips that many pixels inside chart area.
drawActiveElementsOnTopbooleanYesDraw the active points of a dataset over the other points of the dataset.
hoverBackgroundColorString - IsColor - Pattern - GradientYesThe fill color/pattern under the area, when hovered.
hoverBorderCapStyleCapStyleYesCap style of the area, when hovered. See MDN.
hoverBorderColorString - IsColor - GradientYesThe color of the area, when hovered.
hoverBorderDashint[]YesLength and spacing of dashes, when hovered. See MDN.
hoverBorderDashOffsetintYesOffset for area dashes, when hovered. See MDN.
hoverBorderJoinStyleJoinStyleYesArea joint style, when hovered. See MDN.
hoverBorderWidthintYesThe width of the area in pixels, when hovered.
indexAxisIndexAxis-The base axis of the dataset. 'IndexAxis.X' for horizontal areas and 'IndexAxis.Y' for vertical areas.
labelString-The label for the dataset which appears in the legend and tooltips.
normalizedboolean-If true, you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized.
orderint-The drawing order of dataset. Also affects order for stacking, tooltip, and legend.
parsingboolean-If false, the data set parsing is disable. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
pointBackgroundColorString[] - IsColor[] - Gradient[]YesThe fill color for points.
pointBorderColorString[] - IsColor[] - Gradient[]YesThe border color for points.
pointBorderWidthint[]YesThe width of the point border in pixels.
pointHitRadiusdouble[]YesThe pixel size of the non-displayed point that reacts to mouse events.
pointHoverBackgroundColorString[] - IsColor[] - Gradient[]YesPoint background color when hovered.
pointHoverBorderColorString[] - IsColor[] - Gradient[]YesPoint border color when hovered.
pointHoverBorderWidthint[]YesBorder width of point when hovered.
pointHoverRadiusdouble[]YesThe radius of the point when hovered.
pointRadiusdouble[]YesThe radius of the point shape. If set to 0, the point is not rendered.
pointRotationdouble[]YesThe rotation of the point in degrees.
pointStylePointStyle[] - Img[] - Canvas[]YesStyle of the point.
showAreaboolean-If false, the area is not drawn for this dataset.
spanGapsboolean - double-If true, areas will be drawn between points with no or null data. If false, points with NaN data will create a break in the area. Can also be a number specifying the maximum gap length to span. The unit of the value depends on the scale used.
steppedboolean - SteppedYesIf the area is shown as a stepped area.
tensiondouble-Bezier curve tension of the area. Set to 0 to draw straight areas. This option is ignored if monotone cubic interpolation is used.
xAxisIDString-The ID of the x axis to plot this dataset on.
yAxisIDString-The ID of the y axis to plot this dataset on.

General

The general options for a area dataset can control behaviors not related to styling or interactions and they are the following:

NameDefaultsDescription
clipUndefined.DOUBLEHow to clip relative to chart area.
drawActiveElementsOnToptrueDraw the active points of a dataset over the other points of the dataset.
indexAxisIndexAxis.XThe base axis of the dataset.
labelnullThe label for the dataset which appears in the legend and tooltips.
normalizedfalseIf true, you provide data with indices that are unique, sorted, and consistent across data sets and provide the normalized.
order0The drawing order of dataset. Also affects order for stacking, tooltip, and legend.
parsingtrueIf false, the data set parsing is disable. If parsing is disabled, data must be sorted and in the formats the associated chart type and scales use internally.
xAxisIDDefaultScaleId.XThe ID of the x axis to plot this dataset on.
yAxisIDDefaultScaleId.YThe ID of the y axis to plot this dataset on.

Point styling

The style of each point of the dataset can be configured by the following properties:

NameDescription
pointBackgroundColorThe fill color for points.
pointBorderColorThe border color for points.
pointBorderWidthThe width of the point border in pixels.
pointHitRadiusThe pixel size of the non-displayed point that reacts to mouse events.
pointRadiusThe radius of the point shape.
pointRotationThe rotation of the point in degrees.
pointStyleStyle of the point.

All above options have got the fallback to the associated Point elements, retrievable by the following statements:

// from chart instance
Point point = chart.getOptions().getElements().getPoint();
// sets options for all area datasets of the chart
point.setRadius(6);
...
// from defaults
Point defaultPoint = Defaults.get().getGlobal().getElements().getPoint();
// sets options for all area datasets of all charts
defaultPoint.setRadius(6);

Area styling

The style of each area of the dataset can be configured by the following properties:

NameDescription
backgroundColorThe fill color under the area.
borderCapStyleCap style of the area.
borderColorThe color of the area.
borderDashLength and spacing of dashes.
borderDashOffsetOffset for area dashes.
borderJoinStyleArea joint style
borderWidthThe width of the area in pixels.
cubicInterpolationModeAlgorithm used to interpolate a smooth curve from the discrete data points.
steppedIf the area is shown as a stepped area.
tensionBezier curve tension of the area.

All above options have got the fallback to the associated Area elements, retrievable by the following statements:

// from chart instance
Area area = chart.getOptions().getElements().getArea();
// sets options for all area datasets of the chart
area.setBorderWidth(6);
...
// from defaults
Area defaultArea = Defaults.get().getGlobal().getElements().getArea();
// sets options for all area datasets of all charts
defaultArea.setBorderWidth(6);

Point interactions

The interaction with each point can be controlled with the following properties:

NameDescription
pointHoverBackgroundColorPoint background color when hovered.
pointHoverBorderColorPoint border color when hovered.
pointHoverBorderWidthBorder width of point when hovered.
pointHoverRadiusThe radius of the point when hovered.

All above options have got the fallback to the associated Point elements, retrievable by the following statements:

// from chart instance
Point point = chart.getOptions().getElements().getPoint();
// sets options for all area datasets of the chart
point.setRadius(6);
...
// from defaults
Point defaultPoint = Defaults.get().getGlobal().getElements().getPoint();
// sets options for all area datasets of all charts
defaultPoint.setRadius(6);

Area interactions

The interaction with each area can be controlled with the following properties:

NameDescription
hoverBackgroundColorThe fill color under the area, when hovered.
hoverBorderCapStyleCap style of the area, when hovered.
hoverBorderColorThe color of the area, when hovered.
hoverBorderDashLength and spacing of dashes, when hovered.
hoverBorderDashOffsetOffset for area dashes, when hovered.
hoverBorderJoinStyleArea joint style, when hovered.
hoverBorderWidthThe width of the area in pixels, when hovered.

All above options have got the fallback to the associated Area elements, retrievable by the following statements:

// from chart instance
Area area = chart.getOptions().getElements().getArea();
// sets options for all area datasets of the chart
area.setBorderWidth(6);
...
// from defaults
Area defaultArea = Defaults.get().getGlobal().getElements().getArea();
// sets options for all area datasets of all charts
defaultArea.setBorderWidth(6);

Scriptable

Scriptable options at dataset level accept a callback which is called for each of the underlying data values. See more details in Configuring charts section.

// creates chart
AreaChart chart = new AreaChart();
// creates dataset
AreaDataset dataset = chart.newDataset();
// sets the option by a callback
dataset.setBackgroundColor(new ColorCallback<DatasetContext>(){

@Override
public IsColor invoke(DatasetContext context){
// logic
return color;
}
});

The following options can be set by a callback:

NameCallbackReturned types
backgroundColorColorCallback<DatasetContext>String - IsColor - Pattern - Gradient
borderCapStyleCapStyleCallback<DatasetContext>CapStyle
borderColorColorCallback<DatasetContext>String - IsColor - Gradient
borderDashBorderDashCallback<DatasetContext>List<Integer>
borderDashOffsetBorderDashOffsetCallback<DatasetContext>double
borderJoinStyleJoinStyleCallback<DatasetContext>JoinStyle
borderWidthWidthCallback<DatasetContext>int
cubicInterpolationModeCubicInterpolationModeCallbackCubicInterpolationMode
drawActiveElementsOnTopDrawActiveElementsOnTopCallbackboolean
hoverBackgroundColorColorCallback<DatasetContext>String - IsColor - Pattern - Gradient
hoverBorderCapStyleCapStyleCallback<DatasetContext>CapStyle
hoverBorderColorColorCallback<DatasetContext>String - IsColor - Gradient
hoverBorderDashBorderDashCallback<DatasetContext>List<Integer>
hoverBorderDashOffsetBorderDashOffsetCallback<DatasetContext>int
hoverBorderJoinStyleJoinStyleCallback<DatasetContext>JoinStyle
hoverBorderWidthWidthCallback<DatasetContext>int
pointBackgroundColorColorCallback<DatasetContext>String - IsColor - Gradient
pointBorderColorColorCallback<DatasetContext>String - IsColor - Gradient
pointBorderWidthWidthCallback<DatasetContext>int
pointHitRadiusRadiusCallback<DatasetContext>double
pointHoverBackgroundColorColorCallback<DatasetContext>String - IsColor - Gradient
pointHoverBorderColorColorCallback<DatasetContext>String - IsColor - Gradient
pointHoverBorderWidthWidthCallback<DatasetContext>int
pointHoverRadiusRadiusCallback<DatasetContext>double
pointRadiusRadiusCallback<DatasetContext>double
pointRotationRotationCallback<DatasetContext>double
pointStylePointStyleCallback<DatasetContext>boolean - PointStyle - Img - Canvas
steppedSteppedCallbackStepped

Data structure

When the data is an array or list of doubles, the x axis is generally a category. The points are placed onto the axis using their position in the array. When a area chart is created with a category axis, the labels property of the data object must be specified.

// sets data as an array of doubles
dataset.setData(1,2,3,4,6);

// sets data as a list of double
List<Double> list = new LinkedList<>();
list.add(1);
list.add(2);
list.add(3);
dataset.setData(list);

Options

The area chart defines specific options implementation to be configured. These options are merged with the global chart configuration options to form the options passed to the chart.

// creates chart
AreaChart chart = new AreaChart();
// gets the chart options
AreaOptions options = chart.getOptions();
// sets options
options.setResponsive(true);
options.setShowLine(false);

These are the options specific to area charts:

NameTypeDefaultDescription
showLinebooleantrueIf false, the lines between points are not drawn.
spanGapsboolean - doublefalseIf true, areas will be drawn between points with no or null data. If false, points with NaN data will create a break in the area. Can also be a number specifying the maximum gap length to span. The unit of the value depends on the scale used.