分布
直方图
以便于读数的整值为边界划分区间,用柱高表示各区间的观测值数量。
本页内容
直方图展示观测值的分布,包括多数值集中在哪里、分布范围有多广,以及是否偏向一侧。图表以便于读数的整值为边界,把第一个数据系列的观测值分到各个区间。每个区间对应一根柱,柱高表示落入该区间的观测值数量。横轴连续,因此相邻的柱彼此紧贴。
直方图
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">240 requests, in milliseconds</p> </div> <figure class="chart" id="spread"></figure></div><script>addEventListener('DOMContentLoaded', function () {var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) })MasterUI.chart(document.getElementById('spread'), { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach, chart } from '@master/ui/behaviors'var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) })export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => { const detach = [ attach(root.current!), chart(document.getElementById('spread')!, { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }] }), ] return () => detach.forEach(stop => stop()) }, []) return ( <div ref={root} className="card max-w(560) mx-auto"> <div className="card-header"> <h3 className="card-title">Response time</h3> <p className="card-description">240 requests, in milliseconds</p> </div> <figure className="chart" id="spread"></figure> </div> )}<script> import { attach, chart } from '@master/ui/behaviors' var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) }) function mounted(root) { const detach = [ attach(root), chart(document.getElementById('spread'), { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }] }), ] return () => detach.forEach(stop => stop()) }</script><div class="card max-w(560) mx-auto" {@attach mounted}> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">240 requests, in milliseconds</p> </div> <figure class="chart" id="spread"></figure></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, chart } from '@master/ui/behaviors'var readings = Array.from({ length: 240 }, function (_, index) { return Math.round(180 + 60 * Math.sin(index * 1.7) + 40 * Math.cos(index * 0.37) + (index % 23) * 3 + (index % 5 === 0 ? 90 : 0)) })const root = ref(null)let detach = []onMounted(() => { detach = [ attach(root.value), chart(document.getElementById('spread'), { type: 'histogram', label: 'Response time of 240 requests, in milliseconds', series: [{ name: 'Requests', values: readings }] }), ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template> <div ref="root" class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">240 requests, in milliseconds</p> </div> <figure class="chart" id="spread"></figure> </div></template>将原始观测值传入数据系列的 values,不要传入预先统计的次数。各区间的观测值数量由图表计算。用 bins 指定大致的区间数。省略时,图表根据观测值数量自动划分 5 到 20 个区间。区间边界采用便于读数的整值,因此区间可读作“200 到 250”。恰好落在边界上的观测值归入以该边界为起点的区间。
直方图的每根柱对应同一指标的一个数值区间,按区间顺序排列。按类别比较数值时,请使用柱状图。要用五个统计量概括分布,可以使用箱线图。
#选项
| 选项 | 默认值 | |
|---|---|---|
label | 无 | 绘图区的无障碍名称,说明图表展示的内容及其单位 |
series | [] | 每个数据系列包含 name 和与图表类型对应的数据字段:values、value、points、ranges 或 children。还可指定 category、type、low 和 high,以及圆环的 max |
bins | 根据观测值数量确定 | 直方图将观测值划分到的大致区间数 |
min, max, ticks | 自动适配, 4 | 坐标轴的两端及大致的刻度数。散点图的横轴使用 xMin、xMax 和 xTicks |
format, tickFormat | 由区域设置决定 | 数值和刻度的显示格式。散点图的横轴使用 xFormat |
current | 无 | 标记了 aria-current 的数据点索引 |
所有图表类型共用相同的读数显示、键盘操作、图例、颜色和标度。有关这些行为以及所有选项、类和自定义属性,请参阅 图表。