随时间变化
面积图
在线条下方填充同色的淡色区域,可单独显示,也可堆叠以展示总量。
本页内容
面积图在线条下方填充同色,并让颜色向下逐渐淡出。这种填充能突出一两个数据系列。系列更多时,填充区域会相互遮挡,用折线图更容易看清。
面积图
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Requests</h3> <p class="card-description">Millions per month, by region</p> </div> <figure class="chart" id="requests"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('requests'), { type: 'area', label: 'Requests per month by region, in millions', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], series: [ { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] }, { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] } ]})})</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">Requests</h3> <p className="card-description">Millions per month, by region</p> </div> <Chart id="requests" type="area" label="Requests per month by region, in millions" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] }, { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] } ]} /></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">Requests</h3> <p class="card-description">Millions per month, by region</p> </div> <Chart id="requests" type="area" label="Requests per month by region, in millions" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] }, { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] } ]} /></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">Requests</h3> <p class="card-description">Millions per month, by region</p> </div> <Chart id="requests" type="area" label="Requests per month by region, in millions" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" :series="[ { name: 'Tokyo', values: [32, 36, 34, 41, 46, 44, 52, 56, 54, 61, 68, 72] }, { name: 'Frankfurt', values: [12, 14, 18, 17, 22, 26, 25, 30, 34, 33, 39, 42] } ]" /> </div></template>将指针移到某个月份上,或按 Tab 键和方向键,即可查看该月的数值。点击图例项可隐藏对应的数据系列。
#堆叠
当各数据系列组成一个总量时,设置 stacked。各层依次叠加,最上方的边界表示总量。每层用各自的淡色填充,不使用渐变。
堆叠面积图
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Visits</h3> <p class="card-description">Thousands per month, by source</p> </div> <figure class="chart" id="visits"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('visits'), { type: 'area', stacked: true, label: 'Visits per month by source, in thousands', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], series: [ { name: 'Direct', values: [120, 130, 125, 150, 160, 155, 170, 180, 175, 190, 210, 220] }, { name: 'Search', values: [80, 95, 110, 105, 130, 150, 145, 160, 185, 180, 200, 230] }, { name: 'Social', values: [40, 45, 60, 55, 70, 65, 90, 85, 100, 120, 110, 140] } ]})})</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">Visits</h3> <p className="card-description">Thousands per month, by source</p> </div> <Chart id="visits" type="area" stacked label="Visits per month by source, in thousands" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Direct', values: [120, 130, 125, 150, 160, 155, 170, 180, 175, 190, 210, 220] }, { name: 'Search', values: [80, 95, 110, 105, 130, 150, 145, 160, 185, 180, 200, 230] }, { name: 'Social', values: [40, 45, 60, 55, 70, 65, 90, 85, 100, 120, 110, 140] } ]} /></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">Visits</h3> <p class="card-description">Thousands per month, by source</p> </div> <Chart id="visits" type="area" stacked label="Visits per month by source, in thousands" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Direct', values: [120, 130, 125, 150, 160, 155, 170, 180, 175, 190, 210, 220] }, { name: 'Search', values: [80, 95, 110, 105, 130, 150, 145, 160, 185, 180, 200, 230] }, { name: 'Social', values: [40, 45, 60, 55, 70, 65, 90, 85, 100, 120, 110, 140] } ]} /></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">Visits</h3> <p class="card-description">Thousands per month, by source</p> </div> <Chart id="visits" type="area" stacked label="Visits per month by source, in thousands" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" :series="[ { name: 'Direct', values: [120, 130, 125, 150, 160, 155, 170, 180, 175, 190, 210, 220] }, { name: 'Search', values: [80, 95, 110, 105, 130, 150, 145, 160, 185, 180, 200, 230] }, { name: 'Social', values: [40, 45, 60, 55, 70, 65, 90, 85, 100, 120, 110, 140] } ]" /> </div></template>#流图
stacked: 'stream' 让堆叠面积围绕中线分布,不再从基线向上堆叠。这样,每层的位置就不会被下方各层的起伏推移。各层在当前位置的厚度反映该处的数据量,整体轮廓则呈现时宽时窄的变化。流图没有刻度,数值提示会显示各层的数值。
流图
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Listening</h3> <p class="card-description">Hours a month by genre</p> </div> <figure class="chart" id="genres"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('genres'), { type: 'area', stacked: 'stream', label: 'Listening hours a month by genre', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], series: [ { name: 'Rock', values: [20, 24, 30, 28, 22, 18, 16, 20, 26, 30, 34, 30] }, { name: 'Jazz', values: [10, 12, 11, 16, 22, 26, 24, 20, 16, 12, 10, 12] }, { name: 'Pop', values: [14, 12, 16, 20, 24, 30, 36, 32, 26, 20, 16, 18] }, { name: 'Folk', values: [6, 8, 7, 6, 8, 10, 12, 14, 12, 9, 7, 6] } ]})})</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">Listening</h3> <p className="card-description">Hours a month by genre</p> </div> <Chart id="genres" type="area" stacked="stream" label="Listening hours a month by genre" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Rock', values: [20, 24, 30, 28, 22, 18, 16, 20, 26, 30, 34, 30] }, { name: 'Jazz', values: [10, 12, 11, 16, 22, 26, 24, 20, 16, 12, 10, 12] }, { name: 'Pop', values: [14, 12, 16, 20, 24, 30, 36, 32, 26, 20, 16, 18] }, { name: 'Folk', values: [6, 8, 7, 6, 8, 10, 12, 14, 12, 9, 7, 6] } ]} /></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">Listening</h3> <p class="card-description">Hours a month by genre</p> </div> <Chart id="genres" type="area" stacked="stream" label="Listening hours a month by genre" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Rock', values: [20, 24, 30, 28, 22, 18, 16, 20, 26, 30, 34, 30] }, { name: 'Jazz', values: [10, 12, 11, 16, 22, 26, 24, 20, 16, 12, 10, 12] }, { name: 'Pop', values: [14, 12, 16, 20, 24, 30, 36, 32, 26, 20, 16, 18] }, { name: 'Folk', values: [6, 8, 7, 6, 8, 10, 12, 14, 12, 9, 7, 6] } ]} /></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">Listening</h3> <p class="card-description">Hours a month by genre</p> </div> <Chart id="genres" type="area" stacked="stream" label="Listening hours a month by genre" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" :series="[ { name: 'Rock', values: [20, 24, 30, 28, 22, 18, 16, 20, 26, 30, 34, 30] }, { name: 'Jazz', values: [10, 12, 11, 16, 22, 26, 24, 20, 16, 12, 10, 12] }, { name: 'Pop', values: [14, 12, 16, 20, 24, 30, 36, 32, 26, 20, 16, 18] }, { name: 'Folk', values: [6, 8, 7, 6, 8, 10, 12, 14, 12, 9, 7, 6] } ]" /> </div></template>stacked: 'percent' 将每个位置的总量归一化为 100%。各层从 0% 到 100% 填满绘图区,图中显示的是各层所占的比例。
#单个数据系列
只有一个数据系列时,图表默认使用墨色绘制。只有为该系列指定 category 时才会使用类别颜色。
单个数据系列
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Revenue</h3> <p class="card-description">Dollars per month, this year</p> </div> <figure class="chart" id="revenue"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('revenue'), { type: 'area', label: 'Revenue per month, in dollars', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], series: [{ name: 'Revenue', values: [2100, 2400, 2250, 2900, 3300, 3150, 3700, 4100, 3950, 4600, 5200, 5600] }], format: function (value) { return '$' + value.toLocaleString('en-US') }})})</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">Revenue</h3> <p className="card-description">Dollars per month, this year</p> </div> <Chart id="revenue" type="area" label="Revenue per month, in dollars" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[{ name: 'Revenue', values: [2100, 2400, 2250, 2900, 3300, 3150, 3700, 4100, 3950, 4600, 5200, 5600] }]} format={function (value) { return '$' + value.toLocaleString('en-US') }} /></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">Revenue</h3> <p class="card-description">Dollars per month, this year</p> </div> <Chart id="revenue" type="area" label="Revenue per month, in dollars" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[{ name: 'Revenue', values: [2100, 2400, 2250, 2900, 3300, 3150, 3700, 4100, 3950, 4600, 5200, 5600] }]} format={function (value) { return '$' + value.toLocaleString('en-US') }} /></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">Revenue</h3> <p class="card-description">Dollars per month, this year</p> </div> <Chart id="revenue" type="area" label="Revenue per month, in dollars" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" :series="[{ name: 'Revenue', values: [2100, 2400, 2250, 2900, 3300, 3150, 3700, 4100, 3950, 4600, 5200, 5600] }]" :format="function (value) { return '$' + value.toLocaleString('en-US') }" /> </div></template>#选项
| 选项 | 默认值 | |
|---|---|---|
label | 无 | 绘图区的无障碍名称,说明图表展示的内容及其单位 |
labels | [] | 沿坐标轴、雷达图四周或热力图各列上方显示的名称 |
series | [] | 每个数据系列包含 name 和图表类型所需的数据,可为 values、value、points、ranges 或 children,还可指定 category、type、low 和 high,以及环形图的 max |
stacked | false | 堆叠柱条或面积。'percent' 将每组堆叠归一化为 100%,'stream' 让堆叠面积围绕中线分布 |
curve | 'smooth' | smooth、linear 或 step |
min, max, ticks | 自适应, 4 | 坐标轴的取值范围和大致的刻度数。散点图的横轴使用 xMin、xMax 和 xTicks |
format, tickFormat | 随区域设置 | 数值和刻度标签的显示格式。散点图的横轴使用 xFormat |
legend, toggle | 有两个数据系列时显示, true | 是否显示图例,以及是否将图例项显示为复选框 |
各种图表共用同样的数值提示、键盘操作、图例、颜色和刻度机制。图表 文档列出了所有选项、类和自定义属性。