导航

v2.1.0
随时间变化

折线图

逐点连线,展示数值如何随顺序变化。

本页内容

折线按顺序连接各个数值,例如逐月变化的延迟或逐日变化的价格。图中没有柱形时,折线从绘图区的一侧延伸到另一侧。指针所指的数据位置会显示一条细线,各数据系列在该位置的数值用圆点标出。

折线

<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, valuesfalse分别用于标出折线上的每个数据点和显示每根柱形的数值
legend, toggle有两个数据系列时显示, true分别控制是否显示图例,以及图例项是否以复选框呈现

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