如何使用d3.js轴功能绘制指数函数y = ab ^ x [英] How to draw a exponential function y=ab^x using d3.js axis functionality

查看:232
本文介绍了如何使用d3.js轴功能绘制指数函数y = ab ^ x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用d3.js(javascript)库绘制指数函数(y = ab ^ x)。我了解如何自己绘制轴。我只需要绘制实际线条的魔力。我已经看到线性和二次方程的描述,但没有更多的自定义。

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.

推荐答案

我认为你需要自己构建数据。对于指数函数,您可以生成数据:

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)});
}

然后,使用标准代码生成折线图,例如,请参阅 http://bl.ocks.org/3883245

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

这篇关于如何使用d3.js轴功能绘制指数函数y = ab ^ x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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