运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script> <body> <canvas id="myChart" style="width:100%;max-width:600px"></canvas> <script> const xValues = []; const yValues = []; generateData("Math.sin(x)", 0, 10, 0.5); new Chart("myChart", { type: "line", data: { labels: xValues, datasets: [{ fill: false, pointRadius: 2, borderColor: "rgba(0,0,255,0.5)", data: yValues }] }, options: { legend: {display: false}, title: { display: true, text: "y = sin(x)", fontSize: 16 } } }); function generateData(value, i1, i2, step = 1) { for (let x = i1; x <= i2; x += step) { yValues.push(eval(value)); xValues.push(x); } } </script> </body> </html>