網站導覽

v2.1.0
隨時間變化

面積圖

在線條下方填入同色底色,可單獨呈現,也可堆疊顯示總量。

本頁內容

面積圖在線條下方填入同色底色,並向下逐漸淡出,讓一到兩個資料序列在頁面上更醒目。資料序列更多時,底色會互相遮蓋,改用折線圖會更容易判讀。

面積圖

<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
stackedfalse將長條或面積堆疊。'percent' 將每組堆疊的總量視為 100%,'stream' 則讓堆疊面積沿中線置中
curve'smooth'smooth、linear 或 step
min, max, ticks依資料調整, 4刻度的上下限與大致的刻度數量。散佈圖的水平刻度使用 xMin、xMax 和 xTicks
format, tickFormat依語系數值與刻度標籤的顯示格式。散佈圖的水平刻度使用 xFormat
legend, toggle有兩個資料序列時顯示, true是否顯示圖例,以及圖例項目是否為核取方塊

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