I am trying to display a graph on my website. Users enter a function in an input box, and the Javascript library is supposed to display the graph of the function. When I load my current code, the graph doesn't show, and my browser alerts me that functionPlot is not defined.
I have tried to tweak functionPlot into many different forms, but it is not working. I saw that this code worked for someone else on the Web, but it just doesn't work for me. Thank you!
<form id="antoine-input" name="antoine-input" class="form-horizontal my-form" method="POST" action="form.php">
<p>
<input type="text" id="eq" name="eq" value="x+10" />
</p>
</form>
<div id="plot" style="height:650px; width:650px;"></div>
function draw() {
try {
functionPlot({
target: '#plot',
data: [{
fn: document.getElementById('eq').value,
sampler: 'builtIn', //Use the evaluator of math.js
graphType: 'polyline'
}]
});
} catch (err) {
console.log(err);
alert(err);
}
document.getElementById('antoine-input').onsubmit = function(event) {
event.preventDefault();
draw();
};
draw();
}