Created
December 27, 2015 09:14
-
-
Save primats/134f520b55063bf88e59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>math.js | plot</title> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.5.0/math.min.js"></script> | |
<!-- load http://maurizzzio.github.io/function-plot/ --> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<script src="https://wzrd.in/standalone/function-plot@1.14.0"></script> | |
<style> | |
input[type=text] { | |
width: 300px; | |
} | |
input { | |
padding: 6px; | |
} | |
body, html, input { | |
font-family: sans-serif; | |
font-size: 11pt; | |
} | |
form { | |
margin: 20px 0; | |
} | |
</style> | |
</head> | |
<body> | |
<form id="form"> | |
<label for="eq">Enter an equation:</label> | |
<input type="text" id="eq" value="4 * sin(x) + 5 * cos(x/2)" /> | |
<input type="submit" value="Draw" /> | |
</form> | |
<div id="plot"></div> | |
<script> | |
function draw() { | |
try { | |
functionPlot({ | |
target: '#plot', | |
data: [{ | |
fn: document.getElementById('eq').value, | |
sampler: 'builtIn', // this will make function-plot use the evaluator of math.js | |
graphType: 'polyline' | |
}] | |
}); | |
} | |
catch (err) { | |
console.log(err); | |
alert(err); | |
} | |
} | |
document.getElementById('form').onsubmit = function (event) { | |
event.preventDefault(); | |
draw(); | |
}; | |
draw(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment