导航

v2.1.0
关联

散点图

对照两个指标,每个点代表一个对象。

本页内容

散点图用来对照两个指标。每个点代表一个对象,由它的 x 和 y 决定位置。两轴的范围会自动适应数据点,边界采用便于读数的整值,仅在有数据点接近零时才从零开始。要固定范围,请设置 xMin、xMax、min 和 max。指针移到数据点周围也能触发读数显示,读数面板以该点的 label 为标题。

散点图

<div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Responses</h3>    <p class="card-description">Time in milliseconds against size in kilobytes</p>  </div>  <figure class="chart" id="responses"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('responses'), {  type: 'scatter',  label: 'Response time in milliseconds against size in kilobytes',  series: [    { name: 'API', points: [[12, 38], [18, 52], [25, 61], [31, 70], [38, 96], [44, 88], [52, 120], [60, 131], [66, 150], [74, 142], [81, 171]].map(function (pair) { return { x: pair[0], y: pair[1] } }) },    { name: 'Pages', points: [[20, 160], [28, 150], [35, 175], [47, 190], [55, 168], [63, 210], [72, 224], [80, 205], [88, 240]].map(function (pair) { return { x: pair[0], y: pair[1] } }) }  ]})})</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">Responses</h3>    <p className="card-description">Time in milliseconds against size in kilobytes</p>  </div>  <Chart    id="responses"    type="scatter"    label="Response time in milliseconds against size in kilobytes"    series={[      { name: 'API', points: [[12, 38], [18, 52], [25, 61], [31, 70], [38, 96], [44, 88], [52, 120], [60, 131], [66, 150], [74, 142], [81, 171]].map(function (pair) { return { x: pair[0], y: pair[1] } }) },      { name: 'Pages', points: [[20, 160], [28, 150], [35, 175], [47, 190], [55, 168], [63, 210], [72, 224], [80, 205], [88, 240]].map(function (pair) { return { x: pair[0], y: pair[1] } }) }    ]}  /></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">Responses</h3>    <p class="card-description">Time in milliseconds against size in kilobytes</p>  </div>  <Chart    id="responses"    type="scatter"    label="Response time in milliseconds against size in kilobytes"    series={[      { name: 'API', points: [[12, 38], [18, 52], [25, 61], [31, 70], [38, 96], [44, 88], [52, 120], [60, 131], [66, 150], [74, 142], [81, 171]].map(function (pair) { return { x: pair[0], y: pair[1] } }) },      { name: 'Pages', points: [[20, 160], [28, 150], [35, 175], [47, 190], [55, 168], [63, 210], [72, 224], [80, 205], [88, 240]].map(function (pair) { return { x: pair[0], y: pair[1] } }) }    ]}  /></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">Responses</h3>      <p class="card-description">Time in milliseconds against size in kilobytes</p>    </div>    <Chart      id="responses"      type="scatter"      label="Response time in milliseconds against size in kilobytes"      :series="[        { name: 'API', points: [[12, 38], [18, 52], [25, 61], [31, 70], [38, 96], [44, 88], [52, 120], [60, 131], [66, 150], [74, 142], [81, 171]].map(function (pair) { return { x: pair[0], y: pair[1] } }) },        { name: 'Pages', points: [[20, 160], [28, 150], [35, 175], [47, 190], [55, 168], [63, 210], [72, 224], [80, 205], [88, 240]].map(function (pair) { return { x: pair[0], y: pair[1] } }) }      ]"    />  </div></template>

#气泡图

带有 size 的点会显示为气泡,以点的面积表示第三个指标。面积与大小值成正比,所以一个气泡的大小值是另一个的四倍时,显示面积也是四倍。气泡用同一颜色描边和半透明填充,重叠时仍能看清彼此。较大的气泡先绘制,因此叠在大气泡上的小气泡仍能响应指针。

气泡图

<div class="card max-w(560) mx-auto">  <div class="card-header">    <h3 class="card-title">Markets</h3>    <p class="card-description">Growth against share; a bubble is as large as its revenue</p>  </div>  <figure class="chart" id="markets"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('markets'), {  type: 'scatter',  label: 'Markets: growth in percent against share in percent, sized by revenue in millions',  series: [{    name: 'Markets',    points: [      { x: 4, y: 12, size: 40, label: 'Japan' },      { x: 9, y: 20, size: 120, label: 'Germany' },      { x: 14, y: 8, size: 20, label: 'Brazil' },      { x: 18, y: 26, size: 260, label: 'United States' },      { x: 6, y: 30, size: 64, label: 'India' },      { x: 12, y: 16, size: 90, label: 'France' }    ]  }]})})</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">Markets</h3>    <p className="card-description">Growth against share; a bubble is as large as its revenue</p>  </div>  <Chart    id="markets"    type="scatter"    label="Markets: growth in percent against share in percent, sized by revenue in millions"    series={[{      name: 'Markets',      points: [        { x: 4, y: 12, size: 40, label: 'Japan' },        { x: 9, y: 20, size: 120, label: 'Germany' },        { x: 14, y: 8, size: 20, label: 'Brazil' },        { x: 18, y: 26, size: 260, label: 'United States' },        { x: 6, y: 30, size: 64, label: 'India' },        { x: 12, y: 16, size: 90, label: 'France' }      ]    }]}  /></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">Markets</h3>    <p class="card-description">Growth against share; a bubble is as large as its revenue</p>  </div>  <Chart    id="markets"    type="scatter"    label="Markets: growth in percent against share in percent, sized by revenue in millions"    series={[{      name: 'Markets',      points: [        { x: 4, y: 12, size: 40, label: 'Japan' },        { x: 9, y: 20, size: 120, label: 'Germany' },        { x: 14, y: 8, size: 20, label: 'Brazil' },        { x: 18, y: 26, size: 260, label: 'United States' },        { x: 6, y: 30, size: 64, label: 'India' },        { x: 12, y: 16, size: 90, label: 'France' }      ]    }]}  /></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">Markets</h3>      <p class="card-description">Growth against share; a bubble is as large as its revenue</p>    </div>    <Chart      id="markets"      type="scatter"      label="Markets: growth in percent against share in percent, sized by revenue in millions"      :series="[{        name: 'Markets',        points: [          { x: 4, y: 12, size: 40, label: 'Japan' },          { x: 9, y: 20, size: 120, label: 'Germany' },          { x: 14, y: 8, size: 20, label: 'Brazil' },          { x: 18, y: 26, size: 260, label: 'United States' },          { x: 6, y: 30, size: 64, label: 'India' },          { x: 12, y: 16, size: 90, label: 'France' }        ]      }]"    />  </div></template>

人眼判断面积的准确度低于判断位置。把最重要的指标放在坐标轴上,用气泡大小表示只需比较相对大小的指标。

#选项

选项默认值
label无说明图表展示的内容及其单位,用作绘图区的无障碍名称
series[]每个数据系列包含 name 和对应的数据:values、扇区或圆环的 value,或散点图的 points。可选字段包括 category、type 和圆环的 max
min, max, ticks自动适应数据,4刻度范围的两端和大致的刻度间隔数。散点图的横轴使用 xMin、xMax 和 xTicks
format, tickFormat使用区域设置数值和刻度的显示格式。散点图的横轴使用 xFormat
legend, toggle有两个数据系列时显示图例,true是否显示图例,以及图例项是否为复选框

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