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

Function parseSeriesData

apps/chart-maker/main.js:362–405  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

360
361 // 解析系列数据
362 function parseSeriesData() {
363 const input = document.getElementById('series-data-input').value.trim();
364 const labelsInput = document.getElementById('series-labels').value.trim();
365
366 if (!input) {
367 throw new Error('请输入系列数据');
368 }
369
370 if (!labelsInput) {
371 throw new Error('请输入标签数据');
372 }
373
374 const lines = input.split('\n').filter(line => line.trim());
375 const labels = labelsInput.split(',').map(label => label.trim());
376 const datasets = [];
377
378 lines.forEach(line => {
379 const parts = line.split(',').map(part => part.trim());
380 if (parts.length >= 2) {
381 const seriesName = parts[0];
382 const seriesData = parts.slice(1).map(val => {
383 const value = parseFloat(val);
384 if (isNaN(value)) {
385 throw new Error(`"${val}"不是有效的数值`);
386 }
387 return value;
388 });
389
390 datasets.push({
391 label: seriesName,
392 data: seriesData
393 });
394 }
395 });
396
397 if (labels.length === 0 || datasets.length === 0) {
398 throw new Error('无法解析数据,请检查格式是否正确');
399 }
400
401 return {
402 labels: labels,
403 datasets: datasets
404 };
405 }
406
407 // 解析CSV数据
408 function parseCsvData() {

Callers 1

parseInputDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected