JavaScript Multiple Areas Chart

Also known as a Area Graph or Area Chart

The example shows the basic usage of a monopolar area series. The area series is based on line series with the area between the baseline and the given data filled with color. It is drawn on a Cartesian coordinate system and represents the quantitative data.

Current example chart contains two monopolar area series. They are drawn on different sides of the specified baseline and the selected area type specifies the direction. The first area has a positive direction, the second one has a negative direction.

The simple area chart can be created with few simple lines of code:

// Create a new ChartXY.
const chart = lightningChart().ChartXY()

// Add an area series with positive direction using default X and Y axes.
const areaPositive = chart.addAreaSeries({
    baseline: 0,
    type: AreaSeriesTypes.Positive,
})

// Add an area series with negative direction using default X and Y axes.
const areaNegative = chart.addAreaSeries({
    baseline: 0,
    type: AreaSeriesTypes.Negative,
})

The baseline value the type of number and the type can be specified only during the creation of a series instance, where

  • The baseline is a fixed reference level of minimum or starting point used for comparisons, which allow customizing the position of the area.

  • The type of area series is an enum selector which defines the type of area series:

    • Select AreaSeriesTypes.Positive to show the data only above the baseline.
    • Select AreaSeriesTypes.Negative to show the data only below the baseline.
    • Select AreaSeriesTypes.Both to show the data from both sides of the baseline. Bipolar area series will be explained in the future example.

The series accepts points in format { x: number, y: number }. Any number of points can be added with a single call.

// Single point.
series.add({ x: 50, y: 60 })

// Multiple points at once.
series.add([
    { x: 55, y: 60 },
    { x: 60, y: 62 },
    { x: 65, y: 65 },
])