toolbox: {
show: true,
feature: {
mark: { show: true },
dataView: {
show: true, readOnly: true,
optionToContent: function (opt) {
var axisData = opt.xAxis[0].data;
var series = opt.series;
// console.log(series);
// console.log(axisData);
var table =
`<table border="1px solid #ccc" cellspacing="0" cellpadding="10" style="font-size:14px">
<thead style="background:#ccc">
<tr>`;
var th = "", tr = "", td = "";
for (var i = 0; i < axisData.length; i++) {
th += `<th style="padding:5px">${axisData[i]}</th>`
}
series.forEach(item => {
item.data.forEach(item2 => {
td += `<td style="padding:2px 0">${item2}</td>`
})
tr += `<tr><td>${item.name}</td>${td}</tr>`;
td = ""
})
console.log(tr);
table = table + `<th></th>` + th + `</tr></thead>` + `<tbody>` + tr + `</tbody></table>`;
return table;
}
},
magicType: { show: true, type: ['line', 'bar'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
echarts toolbar的数据视图改写成表格
最新推荐文章于 2023-11-28 15:40:03 发布