MongoDB工具 >MongoDB图表 >图表类型 >Text Charts > Number Chart
On this page
Number charts display a single aggregated value from a data field.
Number charts only require a single encoding channel, called Number. This is an aggregation encoding channel which aggregates based on the field and aggregation method chosen, and displays the result in the chart.
Number charts are useful for highlighting grand totals or values which represent the overall state of your data. For example, a store may use a number chart to represent the total dollar value of all sales. Additionally, a hotel chain may use a number chart to represent the average number of vacant rooms across all hotels, or apply a filter to see the total number of vacant rooms in a select region.
The maximum query response size for a number chart is 5000 documents.
The following chart visualizes sales data from a mock office supply store. Each document in the collection represents an individual sale, which contains information on the item(s) sold and the purchaser. This number chart shows the total sum of all sales stored in the collection:
The Number field of items.price
tells MongoDB Charts to
aggregate the field based on the selected method of
$sum. Since
items
is an array, we have to select an array reduction option
before we can aggregate. In this example, we choose
Unwind Array, which creates a new document for each
element in the items
array. MongoDB Charts sums the price
of each
newly created document and displays the value in the visualization.
The following chart visualizes workout data. Each document in the
collection represents an individual workout activity, which contains
information on the type of activity performed and the amount of
calories burned during the workout. This number chart shows the
maximum calories burned across all swimming
and surfing
workouts:
The Number field of Calories Burned (kCal)
tells
MongoDB Charts to aggregate the field based on the selected method of
$max.
We have applied a filter to this chart
to restrict the documents MongoDB Charts examines to only those with an
Activity Type
of Surf
, Swim
, or Indoor Swim
. MongoDB Charts
determines the maximum value of the Calories Burned (kCal)
field
across all documents which match this criteria and displays the value
in the visualization.