分布
直方圖
以易讀的數值為界劃分區間,用長條高度呈現各區間的觀測值筆數。
本頁內容
直方圖呈現觀測值的分布,讓讀者看出資料主要集中在哪裡、分布有多廣,以及是否偏向一側。圖表以易讀的數值為界,將第一個資料序列的觀測值劃入各區間,再用長條的高度表示各區間的筆數。由於下方的刻度是連續的,相鄰區間的長條會彼此相接。
直方圖
<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 指定大約要分成幾個區間。省略時,圖表會依觀測值筆數分成五到二十個區間。區間邊界採用易讀的數值,例如「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 的資料點索引 |
所有圖表形式共用數值顯示、鍵盤操作、圖例、配色與刻度設定。完整的選項、CSS 類別和自訂屬性請參閱 圖表。