網站導覽

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 類別與自訂屬性。