<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
let dataSource = [93, 93, 96, 100, 101, 102, 102];
let xiData = [];
let animationDuration = 4000;
let range = 20,
startPoint = 88;
for (i = 0; i < range; i++) {
xiData[i] = startPoint + i;
}
let data = [];
function GaussKDE(xi, x) {
return (1 / Math.sqrt(2 * Math.PI)) * Math.exp(Math.pow(xi - x, 2) / -2);
}
let N = dataSource.length;
for (i = 0; i < xiData.length; i++) {
let temp = 0;
for (j = 0; j < dataSource.length; j++) {
temp = temp + GaussKDE(xiData[i], dataSource[j]);
}
data.push([xiData[i], (1 / N) * temp]);
}
Highcharts.chart("container", {
chart: {
type: "spline",
animation: true
},
title: {
text: "Gaussian Kernel Density Estimation (KDE)"
},
yAxis: {
title: { text: null }
},
tooltip: {
valueDecimals: 3
},
plotOptions: {
series: {
marker: {
enabled: false
},
dashStyle: "shortdot",
color: "#ff8d1e",
pointStart: xiData[0],
animation: {
duration: animationDuration
}
}
},
series: [
{
name: "KDE",
dashStyle: "solid",
lineWidth: 2,
color: "#1E90FF",
data: data
}
]
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.