gerson
2024-07-09 4a1ab5da5468e7da0dad9641ff6d252ba35a6e00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export const timeDataOptionToContent = (opt) => {
 
    const headerList = [opt.xAxis[0]].concat(opt.yAxis).map((item) => `<td>${item.name}</td>`).join('');
    const title = opt.title?.[0]?.text ?? '';
    let table = '<div style="border:1px solid black"><h3>'+title+'</h3><table style="width:100%;text-align:center"><tbody><tr>' + headerList + '</tr>';
    const timeData = new Set();
    const dataMap = opt.series.map((item) => {
        for (const subItem of item.data) {
            timeData.add(subItem[0]);
        }
        return new Map(item.data);
    });
    const bodyList = Array.from(timeData)
        .toSorted((a, b) => {
            return (a as any).localeCompare(b);
        })
        .map((item) => {
        
            return `<tr><td>${item}</td>${dataMap.map((itemMap) => `<td>${itemMap.get(item) ?? ''}</td>`)}</tr>`;
        }).join('');
    table += bodyList;
 
    table += '</tbody></table></div>';
    return table;
};