4个回答
-
fanting719 初学数据Lv2
abi中自带的箱线图样式和这个不一样,如果需要这样的效果,可以使用统计图组件中的自定义组件,自己写一个这样的图
-
fanting719 初学数据Lv2
function quantile(ascArr, p) {
var H = (ascArr.length - 1) * p + 1;
var h = Math.floor(H);
var v = +ascArr[h - 1];
var e = H - h;
return e ? v + e * (ascArr[h] - v) : v;
}
function test(rawData, opt) {
opt = opt || [];
var boxData = [];
var outliers = [];
var axisData = [];
var boundIQR = opt.boundIQR;
var useExtreme = boundIQR === 'none' || boundIQR === 0;
for (var i = 0; i < rawData.length; i++) {
axisData.push(i + '');
var ascList = echartsesen.number.asc(rawData.slice());
var Q1 = quantile(ascList, 0.25);
var Q2 = quantile(ascList, 0.5);
var Q3 = quantile(ascList, 0.75);
var min = ascList[0];
var max = ascList[ascList.length - 1];
var bound = (boundIQR == null ? 1.5 : boundIQR) * (Q3 - Q1);
var low = useExtreme
? min
: Math.max(min, Q1 - bound);
var high = useExtreme
? max
: Math.min(max, Q3 + bound);
boxData.push([low, Q1, Q2, Q3, high]);
for (var j = 0; j < ascList.length; j++) {
var dataItem = ascList[j];
if (dataItem < low || dataItem > high) {
var outlier = [i, dataItem];
opt.layout === 'vertical' && outlier.reverse();
outliers.push(outlier);
}
}
}
return {
boxData: boxData,
outliers: outliers,
axisData: axisData
};
}
var data = test([
[850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960],
[960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800],
[880, 880, 880, 860, 720, 720, 620, 860, 970, 950, 880, 910, 850, 870, 840, 840, 850, 840, 840, 840],
[890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780],
[890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870]
]);
var option = {
tooltip: {
trigger: 'item',
axisPointer: {
type: 'shadow'
}
},
grid: {
top:'7%',
left: '15%',
right: '5%',
bottom:"15%"
},
xAxis: {
type: 'category',
data: data.axisData,
boundaryGap: true,
nameGap: 30,
splitArea: {
show: false
},
axisLabel: {
formatter: ' {value}',
color:'#99b0d2'
},
splitLine: {
show: false
},
axisLine: {
show: true,
lineStyle:{
color:"#2c3468"
}
}
},
yAxis: {
type: 'value',
nameTextStyle:{
color: "#99b0d2"
},
splitArea: {
show: false
},
splitLine: {
show: true,
lineStyle:{
color:"#2c3468"
}
},
axisLabel: {
formatter: '{value}',
color:'#99b0d2'
},
axisLine: {
show: true,
lineStyle:{
color:"#2c3468"
}
},
},
series: [
{
name: 'boxplot',
type: 'boxplot',
data: data.boxData,
itemStyle:{
normal:{
color:"#168efe",
borderColor:"#2cd1c0"
}
},
tooltip: {
formatter: function (param) {
return [
'Experiment ' + param.name + ': ',
'upper: ' + param.data[5],
'Q3: ' + param.data[4],
'median: ' + param.data[3],
'Q1: ' + param.data[2],
'lower: ' + param.data[1]
].join('<br/>');
}
}
},
{
name: 'outlier',
type: 'scatter',
itemStyle:{
normal:{
color:"#fedb65"
}
},
data: data.outliers
}
]
};
return option;
-
fanting719 初学数据Lv2
自定义组件的中的箱线图,直接取数就行了,图是按照传的数据的数组自动生成的,如果数据量很大,可以先把数据处理好,算出中位数、最大数、最小数在传过来