gigantor2012 - 1 month ago 7x

Javascript Question

I am trying to draw an exponential function (y=ab^x) using the d3.js (javascript) library. I understand how to draw the axes themselves. I just need the magic that draws the actual line. I have seen description for the linear and quadratic equations but nothing more custom.

Any help would be appreciated.

Answer

I think that you need to construct the data yourself. For an exponential function, you can generate the data:

```
var data = [],
n = 100,
a = 1,
b = 2;
for (var k = 0; k < 100; k++) {
data.push({x: 0.01 * k, y: a * Math.pow(b, 0.01 * k)});
}
```

and then, use the standard code to generate a line graph, for instance, see http://bl.ocks.org/3883245.

Source (Stackoverflow)

Comments