项目应用到echarts图表组件、官网的demo中出现空数据会断开、经过跟踪调试、修改echarts.js以下代码即可实现断点连线功能(需要将空数据处理成'-'、这样才能均值):
for (var k = 0; k < dimensions.length; k++) { var dim = dimensions[k]; var dimStorage = storage[dim]; if (dataItem == '-')//遇到空值处理、取前后两个数据的平均值 { //debugger; var preItem = null, nextItem = null; for (var j = i - 1; j >= 0; j--) {//从当前数组索引往前找数据 var myItem = parseFloat(data.getItem(j)); if (myItem.toString() != 'NaN') { preItem = myItem; break; } } for (var j = i + 1; j < size; j++) { var myItem = parseFloat(data.getItem(j)); if (myItem.toString() != 'NaN') { nextItem = myItem; break; } } if (preItem != null && nextItem!=null) { dataItem = ((preItem + nextItem) / 2).toFixed(2); } // else if(preItem != null) // { // dataItem = preItem; // } // else if (nextItem != null) { // dataItem = nextItem; // } } // PENDING NULL is empty or zero dimStorage[i] = dimValueGetter(dataItem, dim, i, k); }