运行 ❯
获取您
自身的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 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("x * 2 + 7", 0, 10, 0.5); new Chart("myChart", { type: "line", data: { labels: xValues, datasets: [{ fill: false, pointRadius: 1, borderColor: "rgba(255,0,0,0.5)", data: yValues }] }, options: { legend: {display: false}, title: { display: true, text: "y = x * 2 + 7", fontSize: 16 } } }); function generateData(value, i1, i2, step = 1) { for (let x = i1; x <= i2; x += step) { xValues.push(x); yValues.push(eval(value)); } } </script> </body> </html>