Results:
Loading...

Vue ChartsArea Series

Area series are line series with the area under the line filled, placing more emphasis on the magnitude of the change. Area series additionally support stacking to show the total value and the way individual values relate to the whole.

Single Area Series

To create a simple area chart we need to use series type 'area'. We also have to provide the xKey and yKey properties. A minimal 'area' series config would therefore look like this:

series: [{
    type: 'area',
    xKey: 'year',
    yKey: 'ie',
}]

In the snippet above we are using 'ie' as the yKey to show market share of this internet browser. Using this simple series config produces the following chart:

Even though area series support markers, they are turned off by default for this series type, as this stylisation is the most common.

To enable area markers, all we need to do is add this to the series config:

series: [{
    ...
    marker: {
        enabled: true
    }
}]

Tooltips will be shown on hover, which in this case show percentage values without a % suffix.

The series are designed to work with all kinds of data and are unaware of the nature of the values. So we additionally provide a tooltipRenderer to add the % suffix. After this change, the tooltips will change like so:

Default Area Tooltip
Before
-->
Custom Area Tooltip
After

The final result can be seen in the example below.

Showing labels on top of data points is also an option with the label config. Labels can be enabled independently of series markers. For example, to show bold labels on top of each data point (and in this case a marker) we would use the following config:

series: [{
    ...
    label: {
        fontWeight: 'bold'
    }
}]

The above config is used in the example below. Feel free to open it in Pluker and experiment with other label options.

Multiple Area Series

It is possible to use more than one 'area' series in a single chart. For example, if we want one series to show the magnitude of change in market share of Internet Explorer and the other series the change in market share of Chrome, we could use the following series config:

series: [
    {
        type: 'area',
        xKey: 'year',
        yKey: 'ie'
    },
    {
        type: 'area',
        xKey: 'year',
        yKey: 'chrome'
    }
]

Since multiple area series can overlap, it is a good idea to make the fill translucent, for example using fillOpacity: 0.7.

Note that in the example below we also:

  • Use yName to control the text that the legend displays
  • Enable markers
  • Define custom fill and stroke
  • Make the fill translucent using the fillOpacity config

Stacked Area Series

The stacked: true property controls series stacking behaviour. For example, to have a stacked area chart that shows changes in market share for the most popular internet browsers we could use a config like this:

series: [
    { type: 'area', xKey: 'year', yKey: 'ie', stacked: true },
    { type: 'area', xKey: 'year', yKey: 'firefox', stacked: true },
    { type: 'area', xKey: 'year', yKey: 'safari', stacked: true },
    { type: 'area', xKey: 'year', yKey: 'chrome', stacked: true }
]

This produces the following chart:

Normalized Area Series

Following on from our stacked area series example, if we want to normalize the totals so that for any given year stack levels always added up to a certain value, for example 100%, we could add the following to our series config:

normalizedTo: 100

It's possible to use any non-zero value to normalize to.

Missing Data

Sometimes data for certain items or time periods might be missing.

The chart handles such cases based on whether the xKey or yKey value of a data point is invalid.

The yKey value of a data point is invalid if it’s +/-Infinity, null, undefined or NaN. A data point with an invalid yKey value will be rendered as a gap in the series.

The xKey value of a data point is invalid if it’s a number, object, +/-Infinity, null, undefined or NaN. The chart handles this depending on the X-axis type:

  • For continuous X axes (either a 'time' or 'number' axis), the data point will be skipped altogether.
  • For category X axes the data point will not be skipped. It will be rendered as a category along the X axis.

The following example demonstrates how missing data is handled for a continuous X-axis type (time axis) in Area Series:

  • Initially there is no missing data, all values are valid for their associated axes.
  • Click the Missing Y values button and note that missing Y values are rendered as gaps in the area chart.
  • Click the Missing X values button and note that missing X values causes no data point to be displayed (hence fewer data points shown in the area chart).
  • The second row of buttons allow switching between stacked and grouped area series.

API Reference

Properties available on the AgAreaSeriesOptions<DatumType = any> interface.