前端开发正态图

normalStateList= res.data.content.normalState  //normalStateList自定义的数组从接口中取返回值
const data = normalStateList
for (let i = 0; i < data.length; i++) {
const mean = data.reduce((a: any, b: any) => a + b) / data.length
const variance
= data
.map((x: any) => {
return (x - mean) ** 2
})
.reduce((a: any, b: any) => a + b) / data.length
const StandardDeviation = Math.sqrt(variance)
const convertedData: any = []
for (
let x = mean - data.length * StandardDeviation;
x <= mean + data.length * StandardDeviation;
x++
) {
const y
= (1 / (StandardDeviation * Math.sqrt(2 * Math.PI)))
* Math.exp(-((x - mean) ** 2) / (2 * StandardDeviation ** 2))
convertedData.push([x, y])
}
normalXdata= convertedData.map((item: any[]) => {//normalXdata、normalYdata自定义的数组
return item[0]
})
normalYdata= convertedData.map((item: any[]) => {
return item[1]
})
}

posted @ 2024-06-24 17:53  就这样,  阅读(7)  评论(0编辑  收藏  举报