33 lines
711 B
JavaScript
33 lines
711 B
JavaScript
// chart.js
|
|
let ctx = null;
|
|
|
|
export function drawChart(canvas, history) {
|
|
if (!canvas || !history?.length) return;
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
const rect = canvas.getBoundingClientRect();
|
|
canvas.width = rect.width;
|
|
canvas.height = rect.height;
|
|
|
|
const w = canvas.width;
|
|
const h = canvas.height;
|
|
|
|
ctx.clearRect(0, 0, w, h);
|
|
|
|
const stepX = w / 1000;
|
|
const scaleY = h / 63;
|
|
|
|
ctx.strokeStyle = "#00ff88";
|
|
ctx.beginPath();
|
|
|
|
for (let i = 0; i < history.length; i++) {
|
|
const x = i * stepX;
|
|
const y = h - history[i].value * scaleY; // 👈 FIX
|
|
|
|
if (i === 0) ctx.moveTo(x, y);
|
|
else ctx.lineTo(x, y);
|
|
}
|
|
|
|
ctx.stroke();
|
|
} |