dataView: { //数据视图 show: true, optionToContent: function (opt) { var axisData = opt.xAxis[0].data; // 坐标数据 var series = opt.series; // 折线图数据 var tdHeaders = '<td></td>'; // 表头 series.forEach(function(item) { tdHeaders += '<td style="padding:0px 2px;">' + item.name + '</td>'; //组装表头 }); var table = '<div style="overflow-y:auto;height: 100%;100%;"><table style="text-align:center; border-collapse:collapse;" border="1" ><tbody><tr>' + tdHeaders + '</tr>'; var tdBodys = ''; // 表数据 for (var i = 0, l = axisData.length; i < l; i++) { for (var j = 0; j < series.length; j++) { tdBodys += '<td>' + series[j].data[i] + '</td>'; //组装表数据 } table += '<tr><td style="padding: 0 10px">' + axisData[i] + '</td>' + tdBodys + '</tr>'; tdBodys = ''; } table += '</tbody></table></div>'; return table; }, contentToOption: function (opt) { var axisData = opt.xAxis[0].data; // 坐标数据 var series = opt.series; // 折线图数据 var tdHeaders = '<td></td>'; // 表头 series.forEach(function(item) { tdHeaders += '<td style="padding:0px 2px;">' + item.name + '</td>'; //组装表头 }); var table = '<div style="overflow-y:auto;height: 100%;100%;"><table style="text-align:center; border-collapse:collapse;" border="1" ><tbody><tr>' + tdHeaders + '</tr>'; var tdBodys = ''; // 表数据 for (var i = 0, l = axisData.length; i < l; i++) { for (var j = 0; j < series.length; j++) { tdBodys += '<td>' + series[j].data[i] + '</td>'; //组装表数据 } table += '<tr><td style="padding: 0 10px">' + axisData[i] + '</td>' + tdBodys + '</tr>'; tdBodys = ''; } table += '</tbody></table></div>'; return table; } },
数据视图如果不是readOnly:true,需在optionToContent后边加contentToOption,否则刷新后数据为空