<!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>