Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a exponential function y=ab^x using d3.js axis functionality

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.

like image 238
gigantor2012 Avatar asked Dec 12 '12 22:12

gigantor2012


1 Answers

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.

like image 126
Pablo Navarro Avatar answered Oct 16 '22 00:10

Pablo Navarro