Using NPM packages in fiddle

Viewed 19

I am trying to use the savitzky-golay-generalized function to smooth some data. But as I import from a CDN i get errors that you can check in this Fiddle.

<html style = "background-color:#1B1B1B">
<script src="https://unpkg.com/ml-savitzky-golay-generalized">
</script>

<body style = "background-color:#1B1B1B" >
<div>
  <canvas id="myChart" style ="height : 300px"></canvas>
</div>

<script >


const data = [2521, 4024, 8616, 9420, 13345, 16356, 14602, 20992, 21456, 26450, 32175, 30564, 26169, 35994, 39870, 43968, 46954, 40572, 55594, 40640, 56658, 56914, 66148, 64800]

const options = {
  windowSize: 15,
  derivative: 0,
  polynomial: 3,
};

const noiseLevel = 0.1;
for (let i = 0; i < data.length; i++)
  data[i] =
    Math.sin((i * Math.PI * 2) / data.length) +
    (Math.random() - 0.5) * noiseLevel;
const answer = sgg(data, (Math.PI * 2) / data.length, options);
console.log(answer);  
</script>
</body>
</html>

Would you know how to make it work ?

Thanks a lot

0 Answers
Related