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

2019-09-07 02:12发布

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条回答
Melony?
2楼-- · 2019-09-07 02:38

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

查看更多
登录 后发表回答