如何使用js库,使用两个输入x和y值绘制图形? [英] How to draw the graph using two input x and y value using js library?

查看:124
本文介绍了如何使用js库,使用两个输入x和y值绘制图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>< html>< head> < title> math.js |情节< / title> < script src =http://cdnjs.cloudflare.com/ajax/libs/mathjs/3.2.1/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>输入公式:< / label> < input type =textid =eqvalue =4 * sin(x)+ 5 * cos(x / 2)/> < input type =submitvalue =Draw/>< / form>< div id =plotstyle =position:absolute; top:20%;>< / div> ; script> function draw(){try {functionPlot({target:'#plot',data:[{fn:document.getElementById('eq')。value,sampler:'builtIn',//这将使函数plot评论者math.js graphType:'polyline'}]}); } catch(err){console.log(err); alert(err); }} document.getElementById('form')onsubmit = function(event){event.preventDefault();画(); }; draw();< / script>< / body>< / html>



我有一些代码在类型方程绘制图相同的概念如何绘制两个输入值在x和y值绘制图请帮助我更正我的代码。



例如: x = 10; y = 5输出根据输入值绘制图形。

解决方案

你只是把太高的数字。
try 4 * sin(0.479425538604203)+ 5 * cos(x / 2 * x + 12)


<!DOCTYPE html>
<html>
<head>
  <title>math.js | plot</title>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/3.2.1/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"style="position:absolute;top:20%;"></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>

I have some code in type the equation to draw the graph same concept how to draw the two input values in x and y value to draw the graph please help me to correct my code.

For Example: x=10; y=5 output draw the graph based on input value.

解决方案

It works fine. You just put too high numbers. try 4 * sin(0.479425538604203) + 5 * cos(x/2*x+12)

这篇关于如何使用js库,使用两个输入x和y值绘制图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆