数据生成柱形图:比例与标签 | 星雨笔录
将数据按比例映射为图形高度和标签。
核心: 柱形图可以将数据值除以最大值,换算为百分比高度或宽度。
最小示例:
const scores = [30, 60, 90];
const max = Math.max(...scores);
const heights = scores.map(x => `${x / max * 100}%`);
console.log(heights);
学完能做: 将数据按比例映射为图形高度和标签。
将数据按比例映射为图形高度和标签。
核心: 柱形图可以将数据值除以最大值,换算为百分比高度或宽度。
最小示例:
const scores = [30, 60, 90];
const max = Math.max(...scores);
const heights = scores.map(x => `${x / max * 100}%`);
console.log(heights);
学完能做: 将数据按比例映射为图形高度和标签。