MCPcopy Index your code
hub / github.com/zxlie/FeHelper / parseExcelData

Function parseExcelData

apps/chart-maker/main.js:694–722  ·  view source on GitHub ↗
(jsonData)

Source from the content-addressed store, hash-verified

692
693 // 解析Excel数据
694 function parseExcelData(jsonData) {
695 if (!jsonData || jsonData.length < 2 || !jsonData[0] || jsonData[0].length < 2) {
696 throw new Error('Excel数据格式不正确,至少需要表头行和数据行');
697 }
698
699 // 假设第一行为标题,第一列为标签
700 const labels = jsonData.slice(1).map(row => row && row[0] ? row[0].toString() : '');
701 const datasets = [];
702
703 const headers = jsonData[0].slice(1);
704 headers.forEach((header, i) => {
705 const data = jsonData.slice(1).map(row => {
706 // 确保每个单元格数据都是数值类型
707 if (!row || !row[i + 1]) return 0;
708 const value = parseFloat(row[i + 1]);
709 return isNaN(value) ? 0 : value;
710 });
711
712 datasets.push({
713 label: header ? header.toString() : `系列${i+1}`,
714 data: data
715 });
716 });
717
718 return {
719 labels: labels,
720 datasets: datasets
721 };
722 }
723
724 // 从chart-generator.js中导入图表生成函数
725 function getChartInstance() {

Callers 1

main.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected