echarts中自定义提示框方法

1.散点加回归线图形中,只需要提示最值和回归值

formatter: function (params) {
var arrDatas_wcs = []; //装有误差或误差方差的值数组
var arrDatas_hgs = []; //装有回归值数组
var arrDatas_wc = []; //装有误差或误差方差的 精确 值数组
var arrDatas_hg = []; //装有回归值精确值数组
// console.log(params);
//将误差值和回归值分离出来
params.forEach(function (item, i) {
if (item.seriesType == “scatter”) {
arrDatas_wcs.push(item.value)
} else {
arrDatas_hgs.push(item.value)
}
})
//找到精确的误差值
arrDatas_wcs.forEach(function (shuju, k) {
arrDatas_wc.push(shuju[1])
})
//找到精确的回归值
arrDatas_hgs.forEach(function (shuju, j) {
arrDatas_hg.push(shuju[1])
})
//找到精确的误差值 中的最大和最小值
arrDatas_wc.sort(function (a, b) {
return a - b;
});
var min = arrDatas_wc[0];
console.log(“min”, min)
console.log(“len”, min.toString().replace(’.’, ‘’).length)
if (min.toString().replace(’.’, ‘’).length >= 5) {
min = min.toExponential(4);
}
;
var max = arrDatas_wc[arrDatas_wc.length - 1];
if (max.toString().replace(’.’, ‘’).length >= 5) {
max = max.toExponential(4);
}
var hgData = arrDatas_hg[0];
if (hgData.toString().replace(’.’, ‘’).length >= 5) {
hgData = hgData.toExponential(4);
}
console.log(“max”, max)
//返回要显示的三个数据
return “最大值:” + max + ‘’ + “最小值:” + min + ‘’ + ‘回归值:’ + hgData
},

在这里插入图片描述

2.多条折线图中,显示当前同一x轴对应的多条折线数据
formatter: function (params) {
var dataValue;
dataValue = params[0].axisValue + ‘’
params.forEach(function (item, i) {
dataValue += item.seriesName + ‘:’ + ISscientificNotation(item.value) + ‘’;
});
return dataValue
},
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43121828/article/details/91529430
今日推荐