mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
69 lines
1.3 KiB
HTML
69 lines
1.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>math.js | plot</title>
|
|
<script src="../../dist/math.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="http://brcdn.org/RbDt4b0Shej4JLF7KBQEilNbIiI.js"></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="f(x) = 4 * sin(x) + 5 * cos(x/2)" />
|
|
<input type="submit" value="Draw" />
|
|
</form>
|
|
|
|
<div id="plot"></div>
|
|
|
|
<p>
|
|
Plot library: <a href="https://github.com/maurizzzio/function-plot">https://github.com/maurizzzio/function-plot</a>
|
|
</p>
|
|
|
|
<script>
|
|
function draw() {
|
|
try {
|
|
functionPlot({
|
|
target: '#plot',
|
|
yDomain: [-10, 10],
|
|
xDomain: [-10, 10],
|
|
data: [{
|
|
fn: math.eval(document.getElementById('eq').value)
|
|
}]
|
|
});
|
|
}
|
|
catch (err) {
|
|
console.log(err);
|
|
alert(err);
|
|
}
|
|
}
|
|
|
|
document.getElementById('form').onsubmit = function (event) {
|
|
event.preventDefault();
|
|
draw();
|
|
};
|
|
|
|
draw();
|
|
</script>
|
|
|
|
</body>
|
|
</html> |