Bar chart
Amounts compared as bars on a baseline: side by side, stacked or across.
On this page
Bars compare amounts: a week of days, the quarters of a year. Each stands in the middle of its band on the baseline, and its corners turn at the end away from it. Under the pointer the other bars step back to a tint, at once, and the whole band is what the pointer lands on, so a short bar is as easy to read as a tall one.
Bar
<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>A value under zero hangs from the baseline, which then stands where zero is. A value of nothing leaves a tick on the baseline, so an empty day is still a day.
Above and below zero
<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>#One bar that matters
chart-quiet on the chart turns the bars into a tint and keeps the ink for the point marked aria-current: today in a week, the plan a reader is on. Give its index as current. values: true writes every bar's value at its end, for a few bars whose exact numbers are the point, or for a touch screen, where nothing hovers.
Quiet, with values
<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>#Side by side, or stacked
Several series stand side by side in each band, which compares them with each other. With stacked they stand on each other, which compares the totals and shows what each is made of: only the outermost bar of a stack has turned corners, and a gap of the surface parts the bars. The readout lists a stack from its top, as it is seen.
Side by side
<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>Stacked bars
<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>#As shares of a whole
stacked: 'percent' makes every stack a whole: each bar is as tall as its share of its stack, so the stacks are all the same height and what changes from one to the next is the mix. The readout says each value with its share.
Shares of a whole
<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>#To either side of zero
Values under zero stack downward from the baseline while those above it stack upward, so two series of opposite sign diverge from a line in the middle: agreement and disagreement, income and spending. Give the series their categories yourself, so the two sides keep their colors wherever they stand.
To either side of zero
<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>#Across
horizontal turns the bars across, one row to a name, for a ranking whose names are longer than a column is wide. The names stand beside the rows and the scale under them; a name longer than eighteen letters is cut, and the readout says it whole.
Across
<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>#Lollipops and whiskers
mark: 'lollipop' draws each bar as a stem with a dot at its end. It says the same value with far less ink, which suits many bars or long ones, where a row of solid bars reads as a wall.
Lollipops
<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>A series with low and high, one of each to a label, carries what its values may be: an interval around a mean, the range between runs. It is drawn as a whisker through the bar's end, and the readout says it after the value.
Whiskers
<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>#Many bars, and a line over them
Bands share the width, so a month fits where a week did, and at most a dozen names stand under the plot; every other one gives way when the plot is narrower than 24rem. A series with type: 'line' is drawn as a line over the bars, on the same scale: a target, a moving average. Two measures of different scale are two charts, never one chart with a scale on each side.
Thirty days
<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>#Options
| Option | Default | |
|---|---|---|
label | none | What the chart shows and in what unit: the plot's accessible name |
labels | [] | The names along the scale, around a radar or over a heatmap's columns |
series | [] | Each with a name and what its form reads: values, a value, points, ranges or children; optionally a category, a type, low and high, and a ring's max |
stacked | false | Bars, or areas, stand on each other; 'percent' makes every stack a whole, and 'stream' centers stacked areas on a middle line |
horizontal | false | Bars, ranges, dumbbells and boxes run across |
mark | 'bar' | 'lollipop' draws a bar as a stem with a dot at its end |
min, max, ticks | fit, 4 | The ends of the scale and about how many steps mark it; xMin, xMax and xTicks for a scatter's scale across |
axis | true | Whether the scale's figures are written; false keeps the hairlines alone, for a small chart in a tile |
format, tickFormat | the locale's | How a value and a tick are written; xFormat for a scatter's scale across |
dots, values | false | Mark every point of a line; write every bar's value |
current | none | The index of the point marked aria-current |
legend, toggle | with two series, true | Whether a legend is written, and whether its entries are checkboxes |
The readout, the keys, the legend, the colors and the scale are the same in every form: Chart holds them, with every option, class and custom property.