網站導覽

v2.1.0
比較

區間圖

用兩個數值呈現每個區間的起點與終點。

本頁內容

區間圖以長條連接每個區間的起點與終點,例如每月的最低與最高氣溫、店家的營業時段,或薪資級距。資料序列的 ranges 中,每個區間都是一對數值。長條兩端皆為圓角,直接畫在兩個端點之間。由於長條的長度代表兩端的差值,刻度會依各區間的範圍調整,無須從零開始。

區間圖

<div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Temperature</h3>    <p class="card-description">Lowest and highest by month, in degrees Celsius</p>  </div>  <figure class="chart" id="temperature"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('temperature'), {  type: 'range',  label: 'Lowest and highest temperature by month, in degrees Celsius',  labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],  series: [{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }],  format: function (value) { return value + '°' }})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { Chart } from './ui/chart'<div className="card max-w(560) mx-auto">  <div className="card-header">    <h3 className="card-title">Temperature</h3>    <p className="card-description">Lowest and highest by month, in degrees Celsius</p>  </div>  <Chart    id="temperature"    type="range"    label="Lowest and highest temperature by month, in degrees Celsius"    labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}    series={[{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }]}    format={function (value) { return value + '°' }}  /></div>
<script>  import Chart from './ui/Chart.svelte'</script><div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Temperature</h3>    <p class="card-description">Lowest and highest by month, in degrees Celsius</p>  </div>  <Chart    id="temperature"    type="range"    label="Lowest and highest temperature by month, in degrees Celsius"    labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}    series={[{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }]}    format={function (value) { return value + '°' }}  /></div>
<script setup>import Chart from './ui/Chart.vue'</script><template>  <div class="card max-w(560) mx-auto">    <div class="card-header">      <h3 class="card-title">Temperature</h3>      <p class="card-description">Lowest and highest by month, in degrees Celsius</p>    </div>    <Chart      id="temperature"      type="range"      label="Lowest and highest temperature by month, in degrees Celsius"      :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']"      :series="[{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }]"      :format="function (value) { return value + '°' }"    />  </div></template>

有多個資料序列時,各序列會像長條圖一樣,在每個分類內並排顯示。啟用 horizontal 後,標籤會由上往下排列,刻度則沿水平方向延伸,適合呈現時間區間或容納直式欄位放不下的長名稱。若需要讓讀者移動及調整計畫中的區間長度,可使用甘特圖。

#選項

選項預設
label無說明圖表呈現的內容與單位,作為繪圖區的無障礙名稱
labels[]沿刻度、雷達圖周圍或熱圖各欄上方顯示的名稱
series[]每個資料序列都有 name,並依圖表類型提供 values、value、points、ranges 或 children。可選填 category、type、low 和 high,以及圓環的 max
horizontalfalse以橫向呈現長條圖、區間圖、啞鈴圖與盒鬚圖
min, max, ticks依資料調整、4刻度範圍的兩端與大致的刻度數量。散佈圖的橫軸使用 xMin、xMax 和 xTicks
format, tickFormat依地區設定數值與刻度標籤的顯示格式。散佈圖的橫軸使用 xFormat
current無標有 aria-current 的資料點索引
legend, toggle有兩個資料序列時顯示、true是否顯示圖例,以及是否將圖例項目呈現為核取方塊

各種圖表共用數值提示、鍵盤操作、圖例、色彩與刻度。圖表 元件提供這些功能,並列出所有選項、CSS 類別與自訂屬性。