导航

v2.1.0
比较

区间图

用两个数值标出每个区间的起点和终点。

本页内容

区间图用一根从起点延伸到终点的条形表示区间,例如每月最低和最高气温、门店营业时段或薪资范围。数据系列的 ranges 中每一项都是一对数值。条形从区间起点悬空绘制,两端为圆角。条形长度表示两端数值之差,因此标度范围随各个区间调整,并不固定从零开始。

区间图

<div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Temperature</h3>    <p class="card-description">Lowest and highest by month, in degrees Celsius</p>  </div>  <figure class="chart" id="temperature"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('temperature'), {  type: 'range',  label: 'Lowest and highest temperature by month, in degrees Celsius',  labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],  series: [{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }],  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">Temperature</h3>    <p className="card-description">Lowest and highest by month, in degrees Celsius</p>  </div>  <Chart    id="temperature"    type="range"    label="Lowest and highest temperature by month, in degrees Celsius"    labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}    series={[{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }]}    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">Temperature</h3>    <p class="card-description">Lowest and highest by month, in degrees Celsius</p>  </div>  <Chart    id="temperature"    type="range"    label="Lowest and highest temperature by month, in degrees Celsius"    labels={['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']}    series={[{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }]}    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">Temperature</h3>      <p class="card-description">Lowest and highest by month, in degrees Celsius</p>    </div>    <Chart      id="temperature"      type="range"      label="Lowest and highest temperature by month, in degrees Celsius"      :labels="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']"      :series="[{ name: 'Tokyo', ranges: [[2, 10], [3, 11], [5, 14], [10, 19], [15, 23], [19, 26], [23, 30], [24, 31], [21, 27], [15, 22], [9, 17], [4, 12]] }]"      :format="function (value) { return value + '°' }"    />  </div></template>

与分组柱状图一样,多个数据系列在每个分类内并排绘制。启用 horizontal 后,标签纵向排列,数值轴横向延伸,适合展示时间区间,或容纳在竖向布局中放不下的长标签。如果需要让用户移动计划中的时间区间或调整其长度,请使用甘特图。

#选项

选项默认值
label无说明图表展示的内容及其单位,用作绘图区的无障碍名称
labels[]沿刻度轴、环绕雷达图或位于热力图各列上方的标签
series[]每个系列包含 name 和对应图表类型所需的数据,即 values、value、points、ranges 或 children;还可指定 category、type、low 和 high,以及圆环的 max
horizontalfalse横向绘制条形、区间、哑铃和箱体
min, max, ticks自动适配, 4刻度范围的两端及大致的刻度数;散点图的横轴使用 xMin、xMax 和 xTicks
format, tickFormat由区域设置决定数值和刻度的显示格式;散点图的横轴使用 xFormat
current无标有 aria-current 的数据点索引
legend, toggle有两个数据系列时显示, true分别控制是否显示图例,以及图例项是否以复选框呈现

所有图表类型共用相同的读数提示、键盘操作、图例、配色和刻度机制。图表 组件文档列出了全部选项、CSS 类和自定义属性。