- Chart Types >
- Line and Area Charts

# Line and Area Charts¶

On this page

Line charts and area charts display information as a series of data points connected by straight line segments. In area charts, the space beneath the line segments is filled in with color, whereas in line charts only the line segments are rendered with no additional coloring or shading. These charts facilitate visualizing data over a period of time and identifying trends and patterns across the entire data range. Line and area charts support visualuzing both discrete and continuous data.

## Discrete Line and Area Charts¶

Discrete line and area charts visualize categorical or binned data with some form of logical ordering, such as time. MongoDB Charts always aggregates values in discrete charts such that any number of documents can supply values to a given plotted point. A discrete chart would be useful to visualize a store’s average annual sales over time.

### Discrete Chart Encoding Channels¶

Discrete line and area charts provide the following encoding channels:

Encoding Channel | Description |
---|---|

X Axis | The category encoding channel. MongoDB Charts renders a data point for each unique value from the field assigned to this encoding channel. |

Y Axis | The aggregation encoding channel. This channel dictates which field to aggregate on and the type of aggregation to perform. This ultimately dictates the position of each category’s data point on the chart. Categories are defined by the X Axis encoding channel. Note You can aggregate upon multiple fields in your dataset to create multi-series charts. For more information, see Multiple Field Mappings. |

Series | ( Note This option is only available when there is a |

### 100% Stacked Area Charts¶

100% stacked area charts are a subtype of discrete area charts. In 100% stacked area charts, the total area shown is normalized to 100% and split into segments based on the category in the Series encoding channel. Each series is shown as a percentage of the whole.

When using a traditional stacked area chart, it can be difficult to compare the proportions of each series to the whole if the total value of the chart segments greatly differ. 100% stacked charts make it easier to compare proportions of each series to the whole by showing relative percentages.

For a detailed example, see the 100% Stacked Area Chart Example.

## Continuous Line and Area Charts¶

In continuous line and area charts, every data point comes from a distinct document in the data source. Continuous charts do not support aggregation or binning. A continuous chart would be useful to visualize stock closing prices over time, assuming each closing price comes from a distinct document in the dataset.

### Continuous Chart Encoding Channels¶

Continuous line and area charts provide the following encoding channels:

Encoding Channel | Description |
---|---|

X Axis | MongoDB Charts renders a data point for the values in this field from each document in the collection. |

Y Axis | For each document in the data source, MongoDB Charts compares the value of this field against the X Axis field and plots the resulting value. Note You can add multiple value encoding channels to the chart’s Y Axis to create multi-series charts. For more information, see Multiple Field Mappings. |

Series | ( Note This option is only available when there is a |

## Discrete Area Versus Continuous Area Charts Display¶

Discrete area charts are *stacked*, meaning MongoDB Charts plots each
series above or below the others in the visualization. The chart shows
the total aggregated value of all of the series, so you can easily see
the proportion of each series in relation to the total.

Continuous area charts are *overlaid*, meaning MongoDB Charts plots each
series directly on top of one another in the visualization.

## Use Cases¶

Line charts and area charts are closely related and are both useful for depicting time series data and data with logical ordering. However, there are scenarios when it may be beneficial to use one chart type over the other.

- Consider using a line chart when creating multi-series charts where each series represents an isolated
field. MongoDB Charts stacks multi-series area charts, as shown in
this example, which results
in a chart where the stacked totals appear to share a relationship
contributing to a larger summed value. This may not be desireable
depending on the specific relationships within the data fields.
- The line chart displays the data from each series in-line with one another without stacking, which may provide a more accurate representation of the data as shown in the discrete line chart.

- Area charts are useful for showing an overall trend while also
highlighting relative performances of individual components of
that sum.
- Consider using a discrete area chart when illustrating a
part-to-whole relationship, such as tracking data metrics over
time. An example of this might be showing
`revenue`

compared with`expenses`

over the course of a year. - A continuous area chart would work in this scenario if you were less concerned with the summation of the two fields and instead wanted a more direct comparison of the fields against one another.

- Consider using a discrete area chart when illustrating a
part-to-whole relationship, such as tracking data metrics over
time. An example of this might be showing

Tip

When your data does not have a logical order, consider instead using a bar or column chart to visualize your data. When the order of the data is not important, a bar or column chart can quickly highlight the highest and lowest values in the visualization, which may be more beneficial than suggesting the viewer read the chart from left to right as in a line or area chart.

## Examples¶

### Discrete Area Chart with Multiple Series¶

The following chart visualizes sales data from a mock office supply store. Each document in the collection represents an individual sale with information on the item(s) sold and the customer conducting the purchase. This discrete area chart shows the distribution of customer ages throughout sales in the collection:

The X Axis field of `customer.age`

plots the ages of the
customers along the X axis. We direct to Charts to bin the ages into groups of 5.

The Y Axis field of `customer.age`

and
aggregate option of count counts the
occurrences of each age in the corresponding bin.

Lastly, we apply the `item.name`

field to the
Series encoding channel to split the age area into
segments displaying the count of each age group purchasing each
store item.

Note

For more information on multi-series charts, see Multi-Series Charts.

### 100% Stacked Area Chart¶

The following chart visualizes data from a mock office supply store. Each document in the collection represents an individual sale with information on the item(s) sold and the customer conducting the purchase. This 100% stacked area chart shows the relative percentages of items sold on each date of the month:

The X Axis field of `saleDate`

plots each sale
according to its date. The Binning and
Periodic settings are enabled, so
Charts groups the dates into bins based on each date of the
month.

Note

For more information on binning dates and the periodic setting, refer to the Bin Data page.

The Y Axis field of `_id`

runs a count aggregation to calculate the
total number of sales that happened each day of the month. Since this
is a 100% stacked chart, these values are all normalized to 100%, and
are segmented by the Series encoding channel.

The Series field of `item.name`

segments the total chart
area based on the name of the item sold. Since there may
be multiple items in a single document, we Unwind this
array to add each item to the visualization. This provides a clear
picture of the relative percentages of items sold based on the
date of the month.

### Discrete Line Chart with Multiple Aggregated Fields¶

The following chart visualizes data pertaining to movies. Each
document in the collection represents a movie and contains general
information about the film and ratings from various rating
aggregators. This discrete line chart compares average
Rotten Tomatoes
`tomato.meter`

ratings and average Metacritic ratings of films over time. Both ratings
are on a scale from `0`

- `100`

:

The X Axis field of `year`

plots each film according to
its release year. We direct to Charts to bin the years into groups of 5.

The Y Axis fields of `tomato.meter`

and `metacritic`

along with the aggregate option of mean
calculate and plot the average ratings of films from each
group of 5 years.

Note

For more information on creating charts with multiple aggregated fields, see Multiple Field Mappings.

### Continuous Line Chart¶

The following chart visualizes data pertaining to the usage of a solar-powered house battery. This continuous line graph shows the battery level over time:

The X Axis field of `timestamp`

plots each timestamp in
the data source. The Y Axis fields of `energy_left`

and
`total_pack_energy`

each plot a series in the chart; the amount of
energy the battery has left and the total amount of energy the battery
holds. This comparison shows how close the battery is to a full charge.

Note

A continuous chart works better than a discrete chart in this case
because our X Axis field, `timestamp`

is not a
discrete, categorical variable, and is instead a continuous value
along a range. We want to plot each `timestamp`

as an individiual
point, rather than show an aggregated value from many data values.