Changed around line 1
+ document.getElementById('file-input').addEventListener('change', function(event) {
+ const file = event.target.files[0];
+ if (file && file.type === 'text/plain') {
+ const reader = new FileReader();
+ reader.onload = function(e) {
+ const text = e.target.result;
+ const data = text.split('\n').map(Number);
+ drawChart(data);
+ };
+ reader.readAsText(file);
+ } else {
+ alert('Please upload a valid .txt file.');
+ }
+ });
+
+ function drawChart(data) {
+ const canvas = document.getElementById('data-chart');
+ const ctx = canvas.getContext('2d');
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+
+ const padding = 20;
+ const width = canvas.width - padding * 2;
+ const height = canvas.height - padding * 2;
+ const maxValue = Math.max(...data);
+ const minValue = Math.min(...data);
+ const xStep = width / (data.length - 1);
+ const yScale = height / (maxValue - minValue);
+
+ ctx.beginPath();
+ ctx.moveTo(padding, height + padding - (data[0] - minValue) * yScale);
+ ctx.strokeStyle = '#50e3c2';
+ ctx.lineWidth = 2;
+
+ data.forEach((value, index) => {
+ const x = padding + index * xStep;
+ const y = height + padding - (value - minValue) * yScale;
+ ctx.lineTo(x, y);
+ });
+
+ ctx.stroke();
+ }