How to render f(x) = 1/x with flot.js?

两盒软妹~` 提交于 2019-12-11 19:35:11

问题


I am considering use flot.js to render the function f(x) = 1/x for 3 cases:

f(x) = 1/n  , 
f(x) = n/x , and 
f(x) = 1/x +n 

I would like to have the student able to change n to see what happens so I will need to refresh the graph as well.

I have no clue how to render the function itself.


回答1:


You have to fill an array with e.g. 100 values and then use that array to plot the graph. Something like this:

var f1array = [];
for (var i = 1; i <= 100; i++) {
    f1array.push([0.1 * i, 1 / (0.1 * i)]);
}
$.plot('#placeholderdiv', [f1array]);

Use this as a starting point and come back if you have further questions.

Edit: fiddle example



来源:https://stackoverflow.com/questions/21711784/how-to-render-fx-1-x-with-flot-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!