長條圖
以基準線上的長條比較數量,可並排、堆疊或橫向呈現。
本頁內容
長條圖用來比較數量,例如一週中每天或一年中各季的數量。每根長條從基準線起始,置於所屬區帶的中央,遠離基準線的一端採圓角。將指標移到某個區帶時,其他長條會立即淡化。整個區帶都能感應指標,因此長條再短也一樣容易查看。
長條圖
<div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Deployments</h3> <p class="card-description">311 this week</p> </div> <figure class="chart" id="deployments" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('deployments'), { type: 'bar', label: 'Deployments per day, this week', labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], series: [{ name: 'Deployments', values: [42, 58, 36, 71, 64, 22, 18] }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(440) mx-auto"> <div className="card-header"> <h3 className="card-title">Deployments</h3> <p className="card-description">311 this week</p> </div> <Chart id="deployments" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" label="Deployments per day, this week" labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']} series={[{ name: 'Deployments', values: [42, 58, 36, 71, 64, 22, 18] }]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Deployments</h3> <p class="card-description">311 this week</p> </div> <Chart id="deployments" style="--chart-height: 11rem" type="bar" label="Deployments per day, this week" labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']} series={[{ name: 'Deployments', values: [42, 58, 36, 71, 64, 22, 18] }]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Deployments</h3> <p class="card-description">311 this week</p> </div> <Chart id="deployments" style="--chart-height: 11rem" type="bar" label="Deployments per day, this week" :labels="['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']" :series="[{ name: 'Deployments', values: [42, 58, 36, 71, 64, 22, 18] }]" /> </div></template>有負值時,基準線會位於零,負值從基準線向下延伸。零值會在基準線上留下一道短線,即使當天數量為零,圖上仍看得到那一天。
高於與低於零
<div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Net change</h3> <p class="card-description">Accounts gained and lost per month</p> </div> <figure class="chart" id="net" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('net'), { type: 'bar', label: 'Net change in accounts per month', labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'], series: [{ name: 'Net change', values: [12, -8, 20, -15, 6, 0, 18, 9] }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(440) mx-auto"> <div className="card-header"> <h3 className="card-title">Net change</h3> <p className="card-description">Accounts gained and lost per month</p> </div> <Chart id="net" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" label="Net change in accounts per month" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']} series={[{ name: 'Net change', values: [12, -8, 20, -15, 6, 0, 18, 9] }]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Net change</h3> <p class="card-description">Accounts gained and lost per month</p> </div> <Chart id="net" style="--chart-height: 11rem" type="bar" label="Net change in accounts per month" labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']} series={[{ name: 'Net change', values: [12, -8, 20, -15, 6, 0, 18, 9] }]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Net change</h3> <p class="card-description">Accounts gained and lost per month</p> </div> <Chart id="net" style="--chart-height: 11rem" type="bar" label="Net change in accounts per month" :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']" :series="[{ name: 'Net change', values: [12, -8, 20, -15, 6, 0, 18, 9] }]" /> </div></template>#凸顯一根長條
在圖表上加上 chart-quiet,即可淡化其他長條,並用墨色凸顯以 aria-current 標記的資料點,例如一週中的今天,或讀者目前使用的方案。透過 current 指定該資料點的索引。values: true 會在每根長條的末端顯示數值,適合長條不多且需要查看精確數值的圖表,也適用於無法以指標停駐查看數值的觸控螢幕。
淡化其他長條並顯示數值
<div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Build minutes</h3> <p class="card-description">Thursday so far</p> </div> <figure class="chart chart-quiet" id="minutes" style="--chart-height: 10rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('minutes'), { type: 'bar', current: 3, values: true, label: 'Build minutes per day, this week', labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], series: [{ name: 'Minutes', values: [62, 48, 75, 54, 88, 30, 26] }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(440) mx-auto"> <div className="card-header"> <h3 className="card-title">Build minutes</h3> <p className="card-description">Thursday so far</p> </div> <Chart className="chart-quiet" id="minutes" style={{ '--chart-height': '10rem' } as React.CSSProperties} type="bar" current={3} values label="Build minutes per day, this week" labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']} series={[{ name: 'Minutes', values: [62, 48, 75, 54, 88, 30, 26] }]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Build minutes</h3> <p class="card-description">Thursday so far</p> </div> <Chart class="chart-quiet" id="minutes" style="--chart-height: 10rem" type="bar" current={3} values label="Build minutes per day, this week" labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']} series={[{ name: 'Minutes', values: [62, 48, 75, 54, 88, 30, 26] }]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Build minutes</h3> <p class="card-description">Thursday so far</p> </div> <Chart class="chart-quiet" id="minutes" style="--chart-height: 10rem" type="bar" :current="3" values label="Build minutes per day, this week" :labels="['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']" :series="[{ name: 'Minutes', values: [62, 48, 75, 54, 88, 30, 26] }]" /> </div></template>#並排或堆疊
多個資料序列會在各區帶內並排,方便彼此比較。設定 stacked 後,長條會堆疊起來,方便比較總量並看出各組的組成。每組只有最外端的長條採圓角,各長條之間留有一道露出底色的間隙。數值提示依圖上的順序,由上往下列出各層。
並排
<div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Plan</h3> <p class="card-description">Actual against plan, by quarter</p> </div> <figure class="chart" id="plan" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('plan'), { type: 'bar', label: 'Planned and actual revenue by quarter, in thousands of dollars', labels: ['Q1', 'Q2', 'Q3', 'Q4'], series: [ { name: 'Plan', values: [40, 55, 60, 75] }, { name: 'Actual', values: [36, 58, 71, 69] } ]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(440) mx-auto"> <div className="card-header"> <h3 className="card-title">Plan</h3> <p className="card-description">Actual against plan, by quarter</p> </div> <Chart id="plan" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" label="Planned and actual revenue by quarter, in thousands of dollars" labels={['Q1', 'Q2', 'Q3', 'Q4']} series={[ { name: 'Plan', values: [40, 55, 60, 75] }, { name: 'Actual', values: [36, 58, 71, 69] } ]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Plan</h3> <p class="card-description">Actual against plan, by quarter</p> </div> <Chart id="plan" style="--chart-height: 11rem" type="bar" label="Planned and actual revenue by quarter, in thousands of dollars" labels={['Q1', 'Q2', 'Q3', 'Q4']} series={[ { name: 'Plan', values: [40, 55, 60, 75] }, { name: 'Actual', values: [36, 58, 71, 69] } ]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Plan</h3> <p class="card-description">Actual against plan, by quarter</p> </div> <Chart id="plan" style="--chart-height: 11rem" type="bar" label="Planned and actual revenue by quarter, in thousands of dollars" :labels="['Q1', 'Q2', 'Q3', 'Q4']" :series="[ { name: 'Plan', values: [40, 55, 60, 75] }, { name: 'Actual', values: [36, 58, 71, 69] } ]" /> </div></template>堆疊長條
<div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Tickets</h3> <p class="card-description">Opened per day, by priority</p> </div> <figure class="chart" id="tickets" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('tickets'), { type: 'bar', stacked: true, label: 'Tickets opened per day by priority', labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], series: [ { name: 'Low', values: [12, 18, 14, 22, 19, 8, 6] }, { name: 'Normal', values: [20, 24, 18, 30, 26, 10, 9] }, { name: 'Urgent', values: [5, 9, 4, 12, 10, 3, 2] } ]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(440) mx-auto"> <div className="card-header"> <h3 className="card-title">Tickets</h3> <p className="card-description">Opened per day, by priority</p> </div> <Chart id="tickets" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" stacked label="Tickets opened per day by priority" labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']} series={[ { name: 'Low', values: [12, 18, 14, 22, 19, 8, 6] }, { name: 'Normal', values: [20, 24, 18, 30, 26, 10, 9] }, { name: 'Urgent', values: [5, 9, 4, 12, 10, 3, 2] } ]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Tickets</h3> <p class="card-description">Opened per day, by priority</p> </div> <Chart id="tickets" style="--chart-height: 11rem" type="bar" stacked label="Tickets opened per day by priority" labels={['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']} series={[ { name: 'Low', values: [12, 18, 14, 22, 19, 8, 6] }, { name: 'Normal', values: [20, 24, 18, 30, 26, 10, 9] }, { name: 'Urgent', values: [5, 9, 4, 12, 10, 3, 2] } ]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Tickets</h3> <p class="card-description">Opened per day, by priority</p> </div> <Chart id="tickets" style="--chart-height: 11rem" type="bar" stacked label="Tickets opened per day by priority" :labels="['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']" :series="[ { name: 'Low', values: [12, 18, 14, 22, 19, 8, 6] }, { name: 'Normal', values: [20, 24, 18, 30, 26, 10, 9] }, { name: 'Urgent', values: [5, 9, 4, 12, 10, 3, 2] } ]" /> </div></template>#顯示各部分占比
stacked: 'percent' 將每組堆疊的總量視為 100%。每根長條的高度取決於它在組內的占比,因此各組等高,組成比例則隨資料而異。數值提示會列出各部分的數值與占比。
各部分占比
<div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Accounts</h3> <p class="card-description">Share by plan, each quarter</p> </div> <figure class="chart" id="plans" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('plans'), { type: 'bar', stacked: 'percent', label: 'Share of accounts by plan, each quarter', labels: ['Q1', 'Q2', 'Q3', 'Q4'], series: [ { name: 'Free', values: [620, 640, 610, 580] }, { name: 'Pro', values: [240, 300, 360, 420] }, { name: 'Team', values: [60, 90, 130, 190] } ]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(440) mx-auto"> <div className="card-header"> <h3 className="card-title">Accounts</h3> <p className="card-description">Share by plan, each quarter</p> </div> <Chart id="plans" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" stacked="percent" label="Share of accounts by plan, each quarter" labels={['Q1', 'Q2', 'Q3', 'Q4']} series={[ { name: 'Free', values: [620, 640, 610, 580] }, { name: 'Pro', values: [240, 300, 360, 420] }, { name: 'Team', values: [60, 90, 130, 190] } ]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Accounts</h3> <p class="card-description">Share by plan, each quarter</p> </div> <Chart id="plans" style="--chart-height: 11rem" type="bar" stacked="percent" label="Share of accounts by plan, each quarter" labels={['Q1', 'Q2', 'Q3', 'Q4']} series={[ { name: 'Free', values: [620, 640, 610, 580] }, { name: 'Pro', values: [240, 300, 360, 420] }, { name: 'Team', values: [60, 90, 130, 190] } ]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Accounts</h3> <p class="card-description">Share by plan, each quarter</p> </div> <Chart id="plans" style="--chart-height: 11rem" type="bar" stacked="percent" label="Share of accounts by plan, each quarter" :labels="['Q1', 'Q2', 'Q3', 'Q4']" :series="[ { name: 'Free', values: [620, 640, 610, 580] }, { name: 'Pro', values: [240, 300, 360, 420] }, { name: 'Team', values: [60, 90, 130, 190] } ]" /> </div></template>#向零值兩側延伸
負值從基準線向下堆疊,正值則向上堆疊,因此正負號相反的兩個資料序列會從中間的基準線向兩側延伸,例如同意與不同意、收入與支出。請自行指定各資料序列的分類,讓它們無論位於哪一側都能保有各自的顏色。
向零值兩側延伸
<div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Survey</h3> <p class="card-description">Share who disagree and who agree</p> </div> <figure class="chart" id="survey" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('survey'), { type: 'bar', stacked: true, horizontal: true, label: 'Share of answers that disagree and agree, by statement, in percent', labels: ['Easy to set up', 'Fast', 'Well documented', 'Good value'], series: [ { name: 'Disagree', category: 'orange', values: [-12, -24, -18, -30] }, { name: 'Agree', category: 'blue', values: [72, 58, 64, 46] } ]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(520) mx-auto"> <div className="card-header"> <h3 className="card-title">Survey</h3> <p className="card-description">Share who disagree and who agree</p> </div> <Chart id="survey" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" stacked horizontal label="Share of answers that disagree and agree, by statement, in percent" labels={['Easy to set up', 'Fast', 'Well documented', 'Good value']} series={[ { name: 'Disagree', category: 'orange', values: [-12, -24, -18, -30] }, { name: 'Agree', category: 'blue', values: [72, 58, 64, 46] } ]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Survey</h3> <p class="card-description">Share who disagree and who agree</p> </div> <Chart id="survey" style="--chart-height: 11rem" type="bar" stacked horizontal label="Share of answers that disagree and agree, by statement, in percent" labels={['Easy to set up', 'Fast', 'Well documented', 'Good value']} series={[ { name: 'Disagree', category: 'orange', values: [-12, -24, -18, -30] }, { name: 'Agree', category: 'blue', values: [72, 58, 64, 46] } ]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Survey</h3> <p class="card-description">Share who disagree and who agree</p> </div> <Chart id="survey" style="--chart-height: 11rem" type="bar" stacked horizontal label="Share of answers that disagree and agree, by statement, in percent" :labels="['Easy to set up', 'Fast', 'Well documented', 'Good value']" :series="[ { name: 'Disagree', category: 'orange', values: [-12, -24, -18, -30] }, { name: 'Agree', category: 'blue', values: [72, 58, 64, 46] } ]" /> </div></template>#橫向長條
horizontal 讓長條橫向排列,每個名稱占一列,適合名稱超出欄寬的排名圖。名稱顯示在各列旁,刻度位於下方。超過 18 個字元的名稱會截短,數值提示會顯示完整名稱。
橫向
<div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Top pages</h3> <p class="card-description">Visitors in the last 7 days</p> </div> <figure class="chart" id="pages" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('pages'), { type: 'bar', horizontal: true, values: true, label: 'Pages by visitors in the last 7 days', labels: ['Installation', 'Button', 'Dialog', 'Default theme', 'Command'], series: [{ name: 'Visitors', values: [4820, 3112, 2240, 1360, 412] }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(520) mx-auto"> <div className="card-header"> <h3 className="card-title">Top pages</h3> <p className="card-description">Visitors in the last 7 days</p> </div> <Chart id="pages" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" horizontal values label="Pages by visitors in the last 7 days" labels={['Installation', 'Button', 'Dialog', 'Default theme', 'Command']} series={[{ name: 'Visitors', values: [4820, 3112, 2240, 1360, 412] }]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Top pages</h3> <p class="card-description">Visitors in the last 7 days</p> </div> <Chart id="pages" style="--chart-height: 11rem" type="bar" horizontal values label="Pages by visitors in the last 7 days" labels={['Installation', 'Button', 'Dialog', 'Default theme', 'Command']} series={[{ name: 'Visitors', values: [4820, 3112, 2240, 1360, 412] }]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Top pages</h3> <p class="card-description">Visitors in the last 7 days</p> </div> <Chart id="pages" style="--chart-height: 11rem" type="bar" horizontal values label="Pages by visitors in the last 7 days" :labels="['Installation', 'Button', 'Dialog', 'Default theme', 'Command']" :series="[{ name: 'Visitors', values: [4820, 3112, 2240, 1360, 412] }]" /> </div></template>#棒棒糖圖與鬚線
mark: 'lollipop' 會把每根長條畫成一條細線,末端加上一個圓點。這種畫法以更少的筆墨呈現相同數值,適合長條很多或很長、實心長條容易連成一大片的情況。
棒棒糖圖
<div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">Median by endpoint, in milliseconds</p> </div> <figure class="chart" id="endpoints" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('endpoints'), { type: 'bar', mark: 'lollipop', horizontal: true, values: true, label: 'Median response time by endpoint, in milliseconds', labels: ['/search', '/checkout', '/feed', '/profile', '/login'], series: [{ name: 'Median', values: [412, 318, 240, 132, 96] }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(520) mx-auto"> <div className="card-header"> <h3 className="card-title">Response time</h3> <p className="card-description">Median by endpoint, in milliseconds</p> </div> <Chart id="endpoints" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" mark="lollipop" horizontal values label="Median response time by endpoint, in milliseconds" labels={['/search', '/checkout', '/feed', '/profile', '/login']} series={[{ name: 'Median', values: [412, 318, 240, 132, 96] }]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">Median by endpoint, in milliseconds</p> </div> <Chart id="endpoints" style="--chart-height: 11rem" type="bar" mark="lollipop" horizontal values label="Median response time by endpoint, in milliseconds" labels={['/search', '/checkout', '/feed', '/profile', '/login']} series={[{ name: 'Median', values: [412, 318, 240, 132, 96] }]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(520) mx-auto"> <div class="card-header"> <h3 class="card-title">Response time</h3> <p class="card-description">Median by endpoint, in milliseconds</p> </div> <Chart id="endpoints" style="--chart-height: 11rem" type="bar" mark="lollipop" horizontal values label="Median response time by endpoint, in milliseconds" :labels="['/search', '/checkout', '/feed', '/profile', '/login']" :series="[{ name: 'Median', values: [412, 318, 240, 132, 96] }]" /> </div></template>在資料序列中為每個標籤各提供一個 low 和 high,即可呈現數值的可能範圍,例如平均值周圍的區間,或多次測量結果的範圍。圖表會讓鬚線穿過長條末端,數值提示則會在數值後列出這個範圍。
鬚線
<div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Trial</h3> <p class="card-description">Mean score by group, with its interval</p> </div> <figure class="chart" id="trial" style="--chart-height: 11rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('trial'), { type: 'bar', label: 'Mean score by group with its 95% interval', labels: ['Control', 'A', 'B', 'C'], series: [{ name: 'Score', values: [52, 61, 58, 70], low: [46, 55, 49, 64], high: [58, 67, 67, 76] }]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { Chart } from './ui/chart'<div className="card max-w(440) mx-auto"> <div className="card-header"> <h3 className="card-title">Trial</h3> <p className="card-description">Mean score by group, with its interval</p> </div> <Chart id="trial" style={{ '--chart-height': '11rem' } as React.CSSProperties} type="bar" label="Mean score by group with its 95% interval" labels={['Control', 'A', 'B', 'C']} series={[{ name: 'Score', values: [52, 61, 58, 70], low: [46, 55, 49, 64], high: [58, 67, 67, 76] }]} /></div><script> import Chart from './ui/Chart.svelte'</script><div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Trial</h3> <p class="card-description">Mean score by group, with its interval</p> </div> <Chart id="trial" style="--chart-height: 11rem" type="bar" label="Mean score by group with its 95% interval" labels={['Control', 'A', 'B', 'C']} series={[{ name: 'Score', values: [52, 61, 58, 70], low: [46, 55, 49, 64], high: [58, 67, 67, 76] }]} /></div><script setup>import Chart from './ui/Chart.vue'</script><template> <div class="card max-w(440) mx-auto"> <div class="card-header"> <h3 class="card-title">Trial</h3> <p class="card-description">Mean score by group, with its interval</p> </div> <Chart id="trial" style="--chart-height: 11rem" type="bar" label="Mean score by group with its 95% interval" :labels="['Control', 'A', 'B', 'C']" :series="[{ name: 'Score', values: [52, 61, 58, 70], low: [46, 55, 49, 64], high: [58, 67, 67, 76] }]" /> </div></template>#大量長條與上方的折線
各區帶共用繪圖寬度,因此一個月的資料也能放進原先一週的空間。繪圖區下方最多顯示 12 個名稱,寬度小於 24rem 時則每隔一個才顯示。設定 type: 'line' 的資料序列會以折線疊在長條上方,並共用同一組刻度,例如目標值或移動平均。兩項指標若需要不同刻度,請各用一張圖表,不要在同一張圖的兩側各設一組刻度。
三十天
<div class="card max-w(600) mx-auto"> <div class="card-header"> <h3 class="card-title">Requests</h3> <p class="card-description">Thousands per day in November, with the weekly average</p> </div> <figure class="chart" id="november"></figure></div><script>addEventListener('DOMContentLoaded', function () {var requests = [49, 52, 58, 61, 44, 37, 56, 60, 64, 72, 75, 68, 45, 42, 69, 73, 81, 76, 78, 49, 48, 72, 80, 85, 83, 86, 58, 52, 82, 88]var days = requests.map(function (value, index) { return 'Nov ' + (index + 1) })var average = requests.map(function (value, index) { var week = requests.slice(Math.max(0, index - 6), index + 1) return Math.round(week.reduce(function (sum, next) { return sum + next }, 0) / week.length)})MasterUI.chart(document.getElementById('november'), { type: 'bar', label: 'Requests per day in November, in thousands', labels: days, series: [ { name: 'Requests', values: requests }, { name: 'Weekly average', type: 'line', values: average, category: 'orange' } ]})})</script><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach, chart } from '@master/ui/behaviors'var requests = [49, 52, 58, 61, 44, 37, 56, 60, 64, 72, 75, 68, 45, 42, 69, 73, 81, 76, 78, 49, 48, 72, 80, 85, 83, 86, 58, 52, 82, 88]var days = requests.map(function (value, index) { return 'Nov ' + (index + 1) })var average = requests.map(function (value, index) { var week = requests.slice(Math.max(0, index - 6), index + 1) return Math.round(week.reduce(function (sum, next) { return sum + next }, 0) / week.length)})export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => { const detach = [ attach(root.current!), chart(document.getElementById('november')!, { type: 'bar', label: 'Requests per day in November, in thousands', labels: days, series: [ { name: 'Requests', values: requests }, { name: 'Weekly average', type: 'line', values: average, category: 'orange' } ] }), ] return () => detach.forEach(stop => stop()) }, []) return ( <div ref={root} className="card max-w(600) mx-auto"> <div className="card-header"> <h3 className="card-title">Requests</h3> <p className="card-description">Thousands per day in November, with the weekly average</p> </div> <figure className="chart" id="november"></figure> </div> )}<script> import { attach, chart } from '@master/ui/behaviors' var requests = [49, 52, 58, 61, 44, 37, 56, 60, 64, 72, 75, 68, 45, 42, 69, 73, 81, 76, 78, 49, 48, 72, 80, 85, 83, 86, 58, 52, 82, 88] var days = requests.map(function (value, index) { return 'Nov ' + (index + 1) }) var average = requests.map(function (value, index) { var week = requests.slice(Math.max(0, index - 6), index + 1) return Math.round(week.reduce(function (sum, next) { return sum + next }, 0) / week.length) }) function mounted(root) { const detach = [ attach(root), chart(document.getElementById('november'), { type: 'bar', label: 'Requests per day in November, in thousands', labels: days, series: [ { name: 'Requests', values: requests }, { name: 'Weekly average', type: 'line', values: average, category: 'orange' } ] }), ] return () => detach.forEach(stop => stop()) }</script><div class="card max-w(600) mx-auto" {@attach mounted}> <div class="card-header"> <h3 class="card-title">Requests</h3> <p class="card-description">Thousands per day in November, with the weekly average</p> </div> <figure class="chart" id="november"></figure></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach, chart } from '@master/ui/behaviors'var requests = [49, 52, 58, 61, 44, 37, 56, 60, 64, 72, 75, 68, 45, 42, 69, 73, 81, 76, 78, 49, 48, 72, 80, 85, 83, 86, 58, 52, 82, 88]var days = requests.map(function (value, index) { return 'Nov ' + (index + 1) })var average = requests.map(function (value, index) { var week = requests.slice(Math.max(0, index - 6), index + 1) return Math.round(week.reduce(function (sum, next) { return sum + next }, 0) / week.length)})const root = ref(null)let detach = []onMounted(() => { detach = [ attach(root.value), chart(document.getElementById('november'), { type: 'bar', label: 'Requests per day in November, in thousands', labels: days, series: [ { name: 'Requests', values: requests }, { name: 'Weekly average', type: 'line', values: average, category: 'orange' } ] }), ]})onUnmounted(() => detach.forEach(stop => stop()))</script><template> <div ref="root" class="card max-w(600) mx-auto"> <div class="card-header"> <h3 class="card-title">Requests</h3> <p class="card-description">Thousands per day in November, with the weekly average</p> </div> <figure class="chart" id="november"></figure> </div></template>#選項
| 選項 | 預設 | |
|---|---|---|
label | 無 | 說明圖表呈現的內容與單位,作為繪圖區的無障礙名稱 |
labels | [] | 沿刻度排列、環繞雷達圖或位於熱圖各欄上方的名稱 |
series | [] | 每個資料序列都有 name,並依圖表形式提供 values、單一 value、points、ranges 或 children。也可指定 category、type、low 和 high,以及圓環的 max |
stacked | false | 將長條或面積堆疊。'percent' 將每組堆疊的總量視為 100%,'stream' 則讓堆疊面積沿中線置中 |
horizontal | false | 讓長條、區間、啞鈴和盒鬚圖以橫向呈現 |
mark | 'bar' | 'lollipop' 將長條畫成末端帶有圓點的細線 |
min, max, ticks | 依資料調整, 4 | 刻度的上下限與大致的刻度數量。散佈圖的水平刻度使用 xMin、xMax 和 xTicks |
axis | true | 是否顯示刻度數字。false 只保留細線,適合資訊磚中的小圖表 |
format, tickFormat | 依語系 | 數值與刻度標籤的顯示格式。散佈圖的水平刻度使用 xFormat |
dots, values | false | 標記折線上的每個資料點,或顯示每根長條的數值 |
current | 無 | 以 aria-current 標記的資料點索引 |
legend, toggle | 有兩個資料序列時顯示, true | 是否顯示圖例,以及圖例項目是否為核取方塊 |
各種圖表共用數值提示、鍵盤操作、圖例、色彩與刻度。圖表 說明這些功能,並列出所有選項、CSS 類別與自訂屬性。