整體的組成
圓環圖
用環繞中央數值的扇形區塊呈現整體的組成。
本頁內容
圓餅圖和圓環圖都用來呈現整體的組成。每個扇形區塊的大小反映其占總和的比例,相鄰區塊等距分隔,邊角採圓角。將整體分成最多五個部分,其餘歸入「其他」,因為第六個細小區塊難以辨讀。
圓環圖
<div class="card max-w(480) mx-auto"> <div class="card-header"> <h3 class="card-title">Storage</h3> <p class="card-description">248 GB of 500 GB used</p> </div> <figure class="chart chart-split" id="storage" style="--chart-size: 10rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('storage'), { type: 'donut', label: 'Storage used by kind, in gigabytes', center: { value: '248 GB', label: 'Used' }, format: function (value) { return value + ' GB' }, series: [ { name: 'Photos', value: 112 }, { name: 'Video', value: 74 }, { name: 'Documents', value: 38 }, { name: 'Other', value: 24 } ]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(480) mx-auto"> <div className="card-header"> <h3 className="card-title">Storage</h3> <p className="card-description">248 GB of 500 GB used</p> </div> <Chart className="chart-split" id="storage" style={{ '--chart-size': '10rem' } as React.CSSProperties} type="donut" label="Storage used by kind, in gigabytes" center={{ value: '248 GB', label: 'Used' }} format={function (value) { return value + ' GB' }} series={[ { name: 'Photos', value: 112 }, { name: 'Video', value: 74 }, { name: 'Documents', value: 38 }, { name: 'Other', value: 24 } ]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(480) mx-auto"> <div class="card-header"> <h3 class="card-title">Storage</h3> <p class="card-description">248 GB of 500 GB used</p> </div> <Chart class="chart-split" id="storage" style="--chart-size: 10rem" type="donut" label="Storage used by kind, in gigabytes" center={{ value: '248 GB', label: 'Used' }} format={function (value) { return value + ' GB' }} series={[ { name: 'Photos', value: 112 }, { name: 'Video', value: 74 }, { name: 'Documents', value: 38 }, { name: 'Other', value: 24 } ]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(480) mx-auto"> <div class="card-header"> <h3 class="card-title">Storage</h3> <p class="card-description">248 GB of 500 GB used</p> </div> <Chart class="chart-split" id="storage" style="--chart-size: 10rem" type="donut" label="Storage used by kind, in gigabytes" :center="{ value: '248 GB', label: 'Used' }" :format="function (value) { return value + ' GB' }" :series="[ { name: 'Photos', value: 112 }, { name: 'Video', value: 74 }, { name: 'Documents', value: 38 }, { name: 'Other', value: 24 } ]" /> </div></template>圓環圖中央保留一個位置,用來顯示總計或重點項目的數值,由 center 指定。指標移到某個扇形區塊上時,中央會改為顯示該區塊的數值與名稱,讓圓環保持完整可見。在圖表上加上 chart-split CSS 類別,圖例就會在繪圖區旁排成一欄,各項目末端顯示對應區塊的占比。空間不足時,圖例會移到繪圖區下方。
pie 採用相同的呈現方式,中央沒有挖空。--chart-size 設定兩種圖表的寬度,預設為 12rem。hole 設定圓環圖內半徑占外半徑的比例,預設為 .7。
#圓餅圖或圓環圖
圓環圖的中央保留給一個數值,圓餅圖則用整個圓來呈現各個扇形區塊。若要用一條長條呈現各部分的占比,可使用組成明細。
#選項
| 選項 | 預設值 | |
|---|---|---|
label | 無 | 說明圖表呈現的內容和單位,作為繪圖區的無障礙名稱 |
series | [] | 每個資料序列都有 name,並依圖表形式提供 values、扇形區塊或圓環的 value,或散佈圖的 points。可另設 category、type,以及圓環的 max |
format, tickFormat | 依語系 | 資料值和刻度標籤的顯示格式。散佈圖的橫軸刻度格式由 xFormat 指定 |
hole, center | .7, 無 | 圓環圖的挖空比例,以及圓環圖或多環圖中央顯示的內容 |
legend, toggle | 有兩個資料序列時顯示, true | 是否顯示圖例,以及圖例項目是否以核取方塊呈現 |
所有圖表形式共用數值顯示、鍵盤操作、圖例、配色與刻度設定。完整的選項、CSS 類別和自訂屬性請參閱 圖表。