>[info] 度量就是從數(shù)據(jù)到圖形的轉(zhuǎn)化,使得數(shù)據(jù)在展示的時(shí)候可以自定義——數(shù)據(jù)加工操作
例如,數(shù)據(jù)源為:
~~~
const data = [
{ month: 0, value: 1 },
{ month: 1, value: 2 },
{ month: 2, value: 3 }
];
~~~
需要把它進(jìn)行加工,把month字段變成月份,并且顯示為一月,二月、三月的形式。
實(shí)例:
~~~
//以下是關(guān)于數(shù)據(jù)映射scale的demo
const data = [
{ month: 0, value: 1 },
{ month: 1, value: 2 },
{ month: 2, value: 3 }
];
chart.scale('month', {
type: 'cat', // 聲明 type 字段為分類類型
values: [ '一月', '二月', '三月' ], // 重新顯示的值
alias: '月份' // 設(shè)置屬性的別名
});
// 這時(shí)候映射的month就變成了 月份:一月
// 這時(shí)坐標(biāo)軸,tooltip等關(guān)于month的數(shù)據(jù)顯示都改變了
~~~
度量的屬性:
~~~js
{
type: {string}, // 度量的類型
range: {array}, // 數(shù)值范圍區(qū)間,即度量轉(zhuǎn)換的范圍,默認(rèn)為 [0, 1]
alias: {string}, // 為數(shù)據(jù)屬性定義別名,用于圖例、坐標(biāo)軸、tooltip 的個(gè)性化顯示
ticks: {array}, // 存儲(chǔ)坐標(biāo)軸上的刻度點(diǎn)文本信息
tickCount: {number}, // 坐標(biāo)軸上刻度點(diǎn)的個(gè)數(shù),不同的度量類型對(duì)應(yīng)不同的默認(rèn)值
formatter: {function}, // 回調(diào)函數(shù),用于格式化坐標(biāo)軸刻度點(diǎn)的文本顯示,會(huì)影響數(shù)據(jù)在坐標(biāo)軸、圖例、tooltip 上的顯示
}
~~~
