Area Chart
Overview
An area chart is a chart type based on the line chart: it also shows information as a series of data points connected by straight line segments, but the area between the X-axis and the line segments is filled with color or a pattern.
The area chart emphasizes the magnitude of change over time and can be used to highlight the total value across a trend. For example, an area chart displaying profit over time can emphasize the total profit.
This article explains how to create a basic Area chart as well as configure settings that are specific to the type. You can also see the table below to get a brief overview of the Area chart's characteristics:
API | |
---|---|
Modules | Core + Basic Cartesian / Base |
Class | anychart.core.cartesian.series.Area |
DATA | |
Data Fields | x, value |
Multiple Series | YES |
OPTIONS | |
Stacked | Stacked Area, Percent Stacked Area |
Vertical | Vertical Area |
3D | 3D Area |
Error Bars | Area Chart with Error Bars |
SUPPORTED CHART PLOTS | |
Polar | Polar Area, Polygon |
Radar | Radar Area |
Scatter | N/A |
Stock | Stock Area |
RELATED TYPES | |
Spline Area | |
Step Area | |
Range Area | |
Range Spline Area | |
Range Step Area | |
Area Sparkline | |
Polygon | |
SEE ALSO | |
Chartopedia: Area Chart | |
General Settings |
Modules
The Area chart requires adding the Core and Basic Cartesian modules:
<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-core.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-cartesian.min.js"></script>
Alternatively, you can use the Base module, which includes, among other things, the two modules mentioned above:
<script src="https://cdn.anychart.com/releases/8.13.0/js/anychart-base.min.js"></script>
Learn more: Modules.
Quick Start
To create an Area chart, use the anychart.area() chart constructor. If you pass the data to this chart constructor, it creates an Area series.
To create an Area series explicitly, call the area() method.
The following sample demonstrates how a basic Area chart is created:
// create data
var data = [
["January", 10000],
["February", 12000],
["March", 18000],
["April", 11000],
["May", 9000]
];
// create a chart
chart = anychart.area();
// create an area series and set the data
var series = chart.area(data);
// set the container id
chart.container("container");
// initiate drawing the chart
chart.draw();
General Settings
In AnyChart there are many settings that are configured in the same way for all chart types, including the Area chart (for example, legend and interactivity settings).
Read the overview of general settings: General Settings.
Special Settings
Appearance
The appearance settings of an Area chart can be configured in three states: normal, hover, and selected. Use the normal(), hovered(), and selected() methods.
Combine them with the following methods:
- fill() to set the fill
- hatchFill() to set the hatch fill
- stroke() to set the stroke
Also, you can use some other methods from anychart.core.StateSettings.
In the sample below, there are two Area series with appearance settings configured:
// create the first series
var series1 = chart.area(seriesData_1);
// configure the visual settings of the first series
series1.normal().fill("#00cc99", 0.3);
series1.hovered().fill("#00cc99", 0.1);
series1.selected().fill("#00cc99", 0.5);
series1.normal().stroke("#00cc99", 1, "10 5", "round");
series1.hovered().stroke("#00cc99", 2, "10 5", "round");
series1.selected().stroke("#00cc99", 4, "10 5", "round");
// create the second series
var series2 = chart.area(seriesData_2);
// configure the visual settings of the second series
series2.normal().fill("#0066cc", 0.3);
series2.hovered().fill("#0066cc", 0.1);
series2.selected().fill("#0066cc", 0.5);
series2.normal().hatchFill("forward-diagonal", "#0066cc", 1, 15);
series2.hovered().hatchFill("forward-diagonal", "#0066cc", 1, 15);
series2.selected().hatchFill("forward-diagonal", "#0066cc", 1, 15);
series2.normal().stroke("#0066cc");
series2.hovered().stroke("#0066cc", 2);
series2.selected().stroke("#0066cc", 4);
Labels
Labels are text or image elements that can be placed anywhere on any chart (you can enable them on a whole series or in a single point). For text labels, font settings and text formatters are available.
Tooltips
A Tooltip is a text box displayed when a point on a chart is hovered over. There is a number of visual and other settings available: for example, you can edit the text by using font settings and text formatters, change the style of background, adjust the position of a tooltip, and so on.
Scales
When Area chart is used with the ordinal scale and you wish to remove the gaps to the right and left of the area you need to change the ordinal scale mode to 'continuous'
:
chart.xScale().mode('continuous');
Stacked Area
Stacked and percent stacked charts are multiple-series charts where related values are placed atop one another, which allows comparing the the contribution of a value to a total, either in absolute or percentage terms.
In AnyChart, you can enable a special mode of the scale to make series stack together: see Stacked Charts.
To learn about the stacked versions of the Area chart and its modifications, see:
- Stacked Area
- Percent Stacked Area
- Stacked Spline Area
- Percent Stacked Spline Area
- Stacked Step Area
- Percent Stacked Step Area
Vertical Area
Most types of series in AnyChart can be drawn both in horizontal and vertical orientation: Vertical Charts.
Here is information about creating Vertical Area series:
3D Area
Using AnyChart, you can create 3D versions of some chart types, including the Area chart.
To learn about 3D charts in general, see 3D Charts.
The 3D Area chart is described in the following article: 3D Area Chart