整体的构成
环形图
用环形展示整体的各个部分,并在中央突出一个数值。
本页内容
饼图和环形图都用来展示整体的构成。每个扇区的大小对应其占总和的比例,相邻扇区之间的间距固定,边角采用圆角。最多保留五个部分,其余归入“其他”,因为第六个细小的扇区很难辨读。
环形图
<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 类后,图例会在绘图区旁纵向排列,每项末尾显示对应扇区的占比。空间不足时,图例会移到绘图区下方。
pie 与环形图的区别在于没有中心孔。两种图表的宽度均由 --chart-size 控制,默认值为 12rem。hole 表示中心孔半径占环形图半径的比例,默认值为 .7。
#饼图或环形图
环形图在中央留出空间来显示一个数值,饼图的扇区则占据整个圆。如果要在一根条形上展示各部分的构成,请使用构成条。
#选项
| 选项 | 默认值 | |
|---|---|---|
label | 无 | 绘图区的无障碍名称,说明图表展示的内容及其单位 |
series | [] | 每个数据系列包含 name,并按图表类型提供 values、扇区或圆环的 value,或散点图的 points。还可指定 category、type 以及圆环的 max |
format, tickFormat | 由区域设置决定 | 数值和刻度的显示格式。散点图的横轴使用 xFormat |
hole, center | .7, 无 | 环形图的中心孔比例,以及环形图或多个圆环中央显示的内容 |
legend, toggle | 有两个数据系列时显示图例, true | 是否显示图例,以及图例项是否为复选框 |
所有图表类型共用相同的读数显示、按键操作、图例、颜色和刻度。有关这些行为以及所有选项、类和自定义属性,请参阅 图表。