scale属性
ticks是固定的值,如果值域有上限,就用 ticks
max-min是区间值,不固定,如果值的上限不确定,就用 max-min
ticks
ticks是固定的值
// 双 Y轴,左侧百分比,右侧动态适应
const ticks = [0, 8, 16, 24, 32];
const scale = {
percent: {
alias: '百分比',
type: 'linear',
formatter: val => `${val} %`,
tickCount: 5,
ticks: [0, 25, 50, 75, 100],
},
total: {
alias: '总量',
type: 'linear',
formatter: val => `${val} GB`,
tickCount: 5,
ticks,
},
free: {
alias: '空闲',
type: 'linear',
formatter: val => `${val} GB`,
tickCount: 5,
ticks,
},
used: {
alias: '已使用',
type: 'linear',
formatter: val => `${val} GB`,
tickCount: 5,
ticks,
},
time: {
alias: '时间',
type: timeCat ? 'timeCat' : 'time',
formatter: val => formatDate(val),
tickCount: 6,
nice: false,
},
};
<Chart
forceFit
data={data}
padding={padding}
scale={scale}
height={320}
/>
max-min自适应
// 获取最大值
function getMaxValue(data) {
if (!Array.isArray(data)) return 100;
const total = data.map(it => it.total);
return Math.max(...total);
}
const scale = {
percent: {
alias: '百分比',
type: 'linear',
formatter: val => `${val} %`,
tickCount: 5,
ticks: [0, 25, 50, 75, 100], // 百分比
},
total: {
alias: '总量',
type: 'linear',
formatter: val => `${val} GB`,
tickCount: 5,
min: 0,
max,
},
used: {
alias: '已使用',
type: 'linear',
formatter: val => `${val} GB`,
tickCount: 5,
min: 0,
max,
},
time: {
alias: '时间',
type: timeCat ? 'timeCat' : 'time',
formatter: val => formatDate(val),
tickCount: 6,
nice: false,
},
};
<Chart
forceFit
data={data}
padding={padding}
scale={scale}
height={320}
/>