UNPKG

@cainiaofe/cn-ui-charts

Version:
19 lines 482 B
import { isArrayNotEmpty } from "./util"; function calculatePercent(key, item, data) { if (key) { var temp = item[key] || ''; if (typeof temp === 'number') { var total = 0; if (isArrayNotEmpty(data)) { data.forEach(function (item2) { if (typeof item2[key] === "number") { total += item2[key]; } }); } return (temp / total * 100).toFixed(2) + "%"; } } return ''; } export { calculatePercent };