在本页面
折线图和面积图将信息显示为通过直线段连接的一系列数据点。在面积图中,线段下方的空间填充有颜色,而在折线图中,仅渲染线段而没有其他着色或阴影。这些图表有助于可视化一段时间(使用时间序列数据)中的数据,并识别整个数据范围内的趋势和模式。折线图和面积图支持可视化离散数据和连续数据。
离散的线和空间图可视化分类或分级与某种形式的逻辑排序的数据,例如时间。MongoDB图表始终会汇总 离散图表中的值,以便任何数量的文档都可以为给定的绘制点提供值。离散图表对于可视化商店随时间的平均年销售额很有用。
离散折线图和面积图提供以下 编码通道:
编码通道 | 描述 |
---|---|
X轴 | 的类别的编码信道。MongoDB Charts为分配给该编码通道的字段中的每个唯一值呈现一个数据点。 |
Y轴 | 所述聚合编码信道。此通道指示要在哪个字段上进行聚合以及要执行的聚合类型。这最终决定了每个类别的数据点在图表上的位置。类别由X轴编码通道定义。 注意 您可以汇总数据集中的多个字段以创建多系列图表。有关更多信息,请参见 多个字段映射。 |
系列 | (可选)向可视化添加其他类别编码通道。在使用时,MongoDB图表会为该字段中的每个唯一值向可视化添加额外的一行。使用此字段可以映射数据中的其他离散分类字段,而不是多个聚合字段。 注意 This option is only available when there is a single field mapped to the Y Axis aggregation encoding channel. |
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.
The maximum document limit for discrete line and area charts is 5000 documents.
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 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 | (Optional) Adds an additional category encoding channel to the visualization. When utilized, this field adds an additional line to the visualization for each unique value in this field. Note This option is only available when there is a single field mapped to the Y Axis aggregation encoding channel. |
The maximum document limit for continuous line and area charts is 50000 documents.
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.
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.
revenue
compared with
expenses
over the course of a year.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.
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.
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.
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.
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:
图的“ X轴”字段timestamp
在数据源中绘制每个时间戳。所述Y轴的字段energy_left
和
total_pack_energy
每个小区的一系列图表中; 电池剩余的电量和电池容纳的总电量。此比较表明电池充满电后有多近。
注意
在这种情况下,连续图要比离散图更好,因为我们的X轴字段timestamp
不是离散的分类变量,而是沿范围的连续值。我们希望将每个timestamp
点绘制为一个单独的点,而不是显示许多数据值的汇总值。