<!DOCTYPE html>
<html>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<body>
<h1>Using Plotly.js</h1>
<p>Enter Equation:</p>
<p><input id="equation" type="text" value="x * 2 + 17"></p>
<p>
<button onclick='plot("scatter")'>Scatter</button>
<button onclick='plot("lines")'>Draw Line</button>
</p>
<div id="myPlot" style="width:100%;max-width:700px"></div>
<script>
function plot(type) {
const exp = document.getElementById("equation").value;
const xValues = [];
const yValues = [];
let mode = "lines";
if (type == "scatter") {mode = "markers"}
for (let x = 0; x <= 10; x += 1) {
xValues.push(x);
yValues.push(eval(exp));
}
const data = [{x:xValues, y:yValues, mode:mode, type:"scatter"}];
const layout = {title: "y = " + exp};
Plotly.newPlot("myPlot", data, layout);
}
</script>
</body>
</html>