比较
瀑布图
用逐步增减展示数值如何从初值变为终值。
本页内容
瀑布图展示一个数值如何变为另一个数值,例如从期初现金余额开始,经过各笔流入和流出,得到期末现金余额。第一个值从基线画起,之后每一步都从上一步的终点开始。细线将每根柱子的终点连到下一根柱子,便于跟踪累计值。增减通过状态色和数值前的正负号区分。
瀑布图
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Cash</h3> <p class="card-description">Thousands of dollars, January to June</p> </div> <figure class="chart" id="cash" style="--chart-height: 13rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('cash'), { type: 'waterfall', total: 'June', values: true, label: 'Cash from January to June, in thousands of dollars', labels: ['January', 'Sales', 'Refunds', 'Payroll', 'Grants', 'Rent'], series: [{ name: 'Cash', values: [420, 310, -64, -280, 90, -110] }]})})</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">Cash</h3> <p className="card-description">Thousands of dollars, January to June</p> </div> <Chart id="cash" style={{ '--chart-height': '13rem' } as React.CSSProperties} type="waterfall" total="June" values label="Cash from January to June, in thousands of dollars" labels={['January', 'Sales', 'Refunds', 'Payroll', 'Grants', 'Rent']} series={[{ name: 'Cash', values: [420, 310, -64, -280, 90, -110] }]} /></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">Cash</h3> <p class="card-description">Thousands of dollars, January to June</p> </div> <Chart id="cash" style="--chart-height: 13rem" type="waterfall" total="June" values label="Cash from January to June, in thousands of dollars" labels={['January', 'Sales', 'Refunds', 'Payroll', 'Grants', 'Rent']} series={[{ name: 'Cash', values: [420, 310, -64, -280, 90, -110] }]} /></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">Cash</h3> <p class="card-description">Thousands of dollars, January to June</p> </div> <Chart id="cash" style="--chart-height: 13rem" type="waterfall" total="June" values label="Cash from January to June, in thousands of dollars" :labels="['January', 'Sales', 'Refunds', 'Payroll', 'Grants', 'Rent']" :series="[{ name: 'Cash', values: [420, 310, -64, -280, 90, -110] }]" /> </div></template>total 为末尾的合计柱命名,该柱从基线画到合计值。省略该选项时,图表在最后一步变化处结束,适合只列出各项变化的情况。values: true 会在每根变化柱上方显示带正负号的变化量,读数面板还会显示该步之后的累计值。
#增减与状态色
瀑布图是唯一对图形标记使用状态色的图表类型。与 Stat 组件显示变化量时一样,增加用成功色,减少用危险色。每个变化值都会带正负号,读数面板和各数据点的名称也会保留该符号。如果数值上升并非好事,例如成本增加,请在图表的 label 和标题中说明。
#选项
| 选项 | 默认值 | |
|---|---|---|
label | 无 | 图表展示的内容及其单位,用作绘图区的无障碍名称 |
labels | [] | 沿坐标轴、环绕雷达图或位于热力图各列上方的名称 |
series | [] | 每个数据系列包含 name 和对应图表类型所需的数据:values、value、points、ranges 或 children。可选字段包括 category、type、low 和 high,以及环形图的 max |
total | 无 | 瀑布图末尾合计柱的名称 |
min, max, ticks | 自动适应数据,4 | 刻度范围的两端和大致的刻度数量。散点图的横轴使用 xMin、xMax 和 xTicks |
format, tickFormat | 使用区域设置 | 数值和刻度的显示格式。散点图的横轴使用 xFormat |
dots, values | false | 标记折线上的每个数据点,显示每根柱子的数值 |
current | 无 | 标记有 aria-current 的数据点索引 |
所有图表类型共用读数面板、键盘操作、图例、配色和刻度机制。图表 组件文档列出了所有选项、CSS 类和自定义属性。