隨時間變化
折線圖
將依序排列的數值逐點連成線。
本頁內容
折線依序連接各個數值,例如逐月的延遲時間或逐日的價格。圖表中沒有長條時,折線會從繪圖區的一端延伸到另一端。指標移到圖上時,細線會標示所在位置,圓點則會標出各資料序列在該處的數值。
折線
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Latency</h3> <p class="card-description">Median by region, in milliseconds</p> </div> <figure class="chart" id="latency"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('latency'), { type: 'line', label: 'Median latency per month by region, in milliseconds', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], series: [ { name: 'Tokyo', values: [42, 44, 41, 47, 52, 49, 46, 44, 48, 53, 51, 47] }, { name: 'Frankfurt', values: [61, 58, 63, 66, 62, 59, 57, 60, 64, 69, 66, 61] }, { name: 'Virginia', values: [78, 74, 71, 75, 80, 86, 83, 79, 76, 81, 85, 82] } ]})})</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">Latency</h3> <p className="card-description">Median by region, in milliseconds</p> </div> <Chart id="latency" type="line" label="Median latency per month by region, in milliseconds" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Tokyo', values: [42, 44, 41, 47, 52, 49, 46, 44, 48, 53, 51, 47] }, { name: 'Frankfurt', values: [61, 58, 63, 66, 62, 59, 57, 60, 64, 69, 66, 61] }, { name: 'Virginia', values: [78, 74, 71, 75, 80, 86, 83, 79, 76, 81, 85, 82] } ]} /></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">Latency</h3> <p class="card-description">Median by region, in milliseconds</p> </div> <Chart id="latency" type="line" label="Median latency per month by region, in milliseconds" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[ { name: 'Tokyo', values: [42, 44, 41, 47, 52, 49, 46, 44, 48, 53, 51, 47] }, { name: 'Frankfurt', values: [61, 58, 63, 66, 62, 59, 57, 60, 64, 69, 66, 61] }, { name: 'Virginia', values: [78, 74, 71, 75, 80, 86, 83, 79, 76, 81, 85, 82] } ]} /></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">Latency</h3> <p class="card-description">Median by region, in milliseconds</p> </div> <Chart id="latency" type="line" label="Median latency per month by region, in milliseconds" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" :series="[ { name: 'Tokyo', values: [42, 44, 41, 47, 52, 49, 46, 44, 48, 53, 51, 47] }, { name: 'Frankfurt', values: [61, 58, 63, 66, 62, 59, 57, 60, 64, 69, 66, 61] }, { name: 'Virginia', values: [78, 74, 71, 75, 80, 86, 83, 79, 76, 81, 85, 82] } ]" /> </div></template>#曲線
curve 決定如何連接各點。預設的 smooth 會畫出平滑曲線,且不會在各點之間產生資料中沒有的峰值或谷值。linear 以直線連接各點,step 則維持目前的數值,直到下一個點才切換,適合一次跳變的數值,例如方案的席次或價格。
階梯線
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Seats</h3> <p class="card-description">On the plan, this year</p> </div> <figure class="chart" id="seats" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('seats'), { type: 'line', curve: 'step', label: 'Seats on the plan per month', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], series: [{ name: 'Seats', values: [12, 12, 12, 20, 20, 20, 20, 32, 32, 32, 40, 40] }], max: 40})})</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">Seats</h3> <p className="card-description">On the plan, this year</p> </div> <Chart id="seats" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="line" curve="step" label="Seats on the plan per month" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[{ name: 'Seats', values: [12, 12, 12, 20, 20, 20, 20, 32, 32, 32, 40, 40] }]} max={40} /></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">Seats</h3> <p class="card-description">On the plan, this year</p> </div> <Chart id="seats" style="--chart-height: 11rem" type="line" curve="step" label="Seats on the plan per month" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[{ name: 'Seats', values: [12, 12, 12, 20, 20, 20, 20, 32, 32, 32, 40, 40] }]} max={40} /></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">Seats</h3> <p class="card-description">On the plan, this year</p> </div> <Chart id="seats" style="--chart-height: 11rem" type="line" curve="step" label="Seats on the plan per month" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" :series="[{ name: 'Seats', values: [12, 12, 12, 20, 20, 20, 20, 32, 32, 32, 40, 40] }]" :max="40" /> </div></template>#缺值與資料點
數值為 null 時,折線會在該處中斷,該點的數值提示只會列出有數值的資料序列。dots: true 會標示折線上的每個點,而非只標示指標所在的點,適合資料點較少的折線。
缺值與資料點標記
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Uptime</h3> <p class="card-description">Percent per month; no reading in May</p> </div> <figure class="chart" id="uptime" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('uptime'), { type: 'line', curve: 'linear', dots: true, min: 99, max: 100, label: 'Uptime per month, in percent', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'], series: [{ name: 'Uptime', values: [99.92, 99.97, 99.81, 99.95, null, 99.64, 99.9, 99.98] }], format: function (value) { return value + '%' }})})</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">Uptime</h3> <p className="card-description">Percent per month; no reading in May</p> </div> <Chart id="uptime" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="line" curve="linear" dots min={99} max={100} label="Uptime per month, in percent" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']} series={[{ name: 'Uptime', values: [99.92, 99.97, 99.81, 99.95, null, 99.64, 99.9, 99.98] }]} format={function (value) { return value + '%' }} /></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">Uptime</h3> <p class="card-description">Percent per month; no reading in May</p> </div> <Chart id="uptime" style="--chart-height: 11rem" type="line" curve="linear" dots min={99} max={100} label="Uptime per month, in percent" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']} series={[{ name: 'Uptime', values: [99.92, 99.97, 99.81, 99.95, null, 99.64, 99.9, 99.98] }]} format={function (value) { return value + '%' }} /></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">Uptime</h3> <p class="card-description">Percent per month; no reading in May</p> </div> <Chart id="uptime" style="--chart-height: 11rem" type="line" curve="linear" dots :min="99" :max="100" label="Uptime per month, in percent" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']" :series="[{ name: 'Uptime', values: [99.92, 99.97, 99.81, 99.95, null, 99.64, 99.9, 99.98] }]" :format="function (value) { return value + '%' }" /> </div></template>#數值的可能範圍
在資料序列中為每個標籤指定一組 low 和 high,就能呈現數值的可能範圍,例如預測區間或兩次執行結果之間的範圍。圖表會在折線後方以同色的淡色區間帶呈現,數值提示則會在數值後列出這個範圍。
區間帶
<div class="card max-w(560) mx-auto"> <div class="card-header"> <h3 class="card-title">Sessions</h3> <p class="card-description">Thousands per month, with the range the forecast allows</p> </div> <figure class="chart" id="forecast"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('forecast'), { type: 'line', label: 'Sessions per month with the range of the forecast, in thousands', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], series: [{ name: 'Sessions', values: [320, 360, 340, 410, 460, 440, 520, 560, 540, 610, 680, 720], low: [300, 335, 310, 370, 410, 385, 450, 470, 440, 490, 540, 560], high: [340, 385, 372, 452, 512, 498, 592, 650, 640, 730, 820, 880] }]})})</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">Sessions</h3> <p className="card-description">Thousands per month, with the range the forecast allows</p> </div> <Chart id="forecast" type="line" label="Sessions per month with the range of the forecast, in thousands" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[{ name: 'Sessions', values: [320, 360, 340, 410, 460, 440, 520, 560, 540, 610, 680, 720], low: [300, 335, 310, 370, 410, 385, 450, 470, 440, 490, 540, 560], high: [340, 385, 372, 452, 512, 498, 592, 650, 640, 730, 820, 880] }]} /></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">Sessions</h3> <p class="card-description">Thousands per month, with the range the forecast allows</p> </div> <Chart id="forecast" type="line" label="Sessions per month with the range of the forecast, in thousands" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']} series={[{ name: 'Sessions', values: [320, 360, 340, 410, 460, 440, 520, 560, 540, 610, 680, 720], low: [300, 335, 310, 370, 410, 385, 450, 470, 440, 490, 540, 560], high: [340, 385, 372, 452, 512, 498, 592, 650, 640, 730, 820, 880] }]} /></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">Sessions</h3> <p class="card-description">Thousands per month, with the range the forecast allows</p> </div> <Chart id="forecast" type="line" label="Sessions per month with the range of the forecast, in thousands" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']" :series="[{ name: 'Sessions', values: [320, 360, 340, 410, 460, 440, 520, 560, 540, 610, 680, 720], low: [300, 335, 310, 370, 410, 385, 450, 470, 440, 490, 540, 560], high: [340, 385, 372, 452, 512, 498, 592, 650, 640, 730, 820, 880] }]" /> </div></template>#在長條上疊加折線
在長條圖中,設為 type: 'line' 的資料序列會以折線疊加在長條上,並共用同一個刻度,適合呈現目標值或移動平均。
#選項
| 選項 | 預設 | |
|---|---|---|
label | 無 | 說明圖表呈現的內容與單位,作為繪圖區的無障礙名稱 |
labels | [] | 沿刻度、雷達圖周圍或熱圖各欄上方顯示的名稱 |
series | [] | 每個資料序列都有 name,並依圖表類型提供 values、value、points、ranges 或 children。可選填 category、type、low 和 high,以及圓環的 max |
curve | 'smooth' | smooth、linear 或 step |
min, max, ticks | 依資料調整、4 | 刻度範圍的兩端與大致的刻度數量。散佈圖的橫軸使用 xMin、xMax 和 xTicks |
format, tickFormat | 依地區設定 | 數值與刻度標籤的顯示格式。散佈圖的橫軸使用 xFormat |
dots, values | false | 標示折線上的每個點,以及顯示每根長條的數值 |
legend, toggle | 有兩個資料序列時顯示、true | 是否顯示圖例,以及是否將圖例項目呈現為核取方塊 |
各種圖表共用數值提示、鍵盤操作、圖例、色彩與刻度。圖表 元件提供這些功能,並列出所有選項、CSS 類別與自訂屬性。