我是箱线图的新手。我试图找到,是否有一种方法或方法来计算 JavaScript 中的箱线图四分位数、异常值和四分位数。如果是的话,任何人都可以帮助我。而且,如果我总共有 7 或 9 个数字(奇数),这些四分位数将如何计算。我正在使用 High Charts 生成这些箱线图
If I have
data = [1,2,3,4,5,6,7,8,9] then what will be my q1,q2, and q3.
谁能帮我理解这些。提前致谢。
答案 0 :(得分:0)
我找到了通过将数据分组为箱线图来呈现图表的解决方案。 jsfiddle 链接中的解决方案是:
var chart,
numberOfBoxes = 7,
numberOfPoints = 100,
cats = alphaCats(numberOfBoxes),
outliers = [];
$(function() {
$('#container').highcharts({
chart: {
margin: [75, 25, 90, 100]
},
legend: {
enabled: true
},
tooltip: {
shared: true
},
xAxis: {
title: {
text: 'Group'
},
categories: cats,
labels: {
style: {
fontWeight: 'bold'
}
}
},
yAxis: {
title: {
text: 'Distribution'
}
}
});
chart = $('#container').highcharts();
//-----------------------------------------------------
//build the data and add the series to the chart
var boxData = [],
meanData = [];
for (var i = 0; i < numberOfBoxes; i++) {
//generate random data, then calculate box plot values
var data = randomData(
numberOfPoints, //how many points
false, //restrict to positive?
(10 * Math.random()) //random multiplication factor
);
var boxValues = getBoxValues(data, i);
boxData.push(boxValues.values);
meanData.push([i, mean(data)]);
}
console.log(outliers);
chart.addSeries({
id: 'box',
name: 'Box Plots',
type: 'boxplot',
color: Highcharts.getOptions().colors[0],
fillColor: null,
data: boxData
});
chart.addSeries({
id: 'outliers',
name: 'Outliers',
type: 'scatter',
color: Highcharts.getOptions().colors[2],
marker: {
enabled: true,
radius: 2,
fillColor: 'transparent',
lineColor: 'rgba(40,40,56,0.5)',
lineWidth: 1
},
data: boxValues.outliers
});
chart.addSeries({
id: 'mean',
name: 'Means',
type: 'line',
lineWidth: 0,
color: Highcharts.getOptions().colors[1],
marker: {
enabled: true,
symbol: 'diamond',
lineWidth: 0.5,
lineColor: 'rgba(255,255,255,1)',
radius: 2
},
data: meanData
});
})
参考以下链接:
https://jsfiddle.net/jlbriggs/db11fots/