最小cubism.js地平线图示例(TypeError:callback不是一个函数) [英] minimal cubism.js horizon chart example (TypeError: callback is not a function)
问题描述
我有一个时间的魔鬼从d3和立体派API页面上的任何代码改变的东西,我需要他们做什么工作...
I'm having a devil of a time going from any code found on the d3 and cubism API pages to altering things to work with what I need them to do...
我想按照此处列出的Horizon图表的步骤 https:// github.com/square/cubism/wiki/Horizon ,但我没有Cube或Graphite数据源。
I'm trying to follow the steps for a Horizon graph as listed here https://github.com/square/cubism/wiki/Horizon but I don't have a Cube or Graphite data source.
所以我试图使一个来自mbostock的答案的最小示例指标
使用其他数据源进行立体.js
和/或随机值返回度量示例
https://github.com/square/cubism/wiki/Context
So I'm trying to make a minimal example metric from mbostock's answer here Using Other Data Sources for cubism.js and/or the random-value-returning metric example here https://github.com/square/cubism/wiki/Context
我想在Context API页面上,解释参数到context.metric(),我不明白的部分...和结果可用时的回调函数。我在我的服务器上有以下,当我在浏览器中查看/刷新时,我在浏览器的控制台中得到TypeError:callback is not a function:
I guess on that Context API page, where it explains the parameters to context.metric(), I don't understand the part "...and the callback function for when results are available". I have the following on my server and when I view/refresh in my browser I get "TypeError: callback is not a function" in my browser's console:
<body>
<div class="mag"></div>
<script type="text/javascript">
var myContext = cubism.context();
var myHoriz = myContext.horizon()
.metric(function(start, stop, step, callback) {
var values = [];
start = +start;
stop = +stop;
while (start < stop) {
start += step;
values.push(Math.random());
}
callback(null, values);
});
d3.select(".mag").selectAll("p")
.data([1, 2, 3, 7]) // the "times" for which I want to graph the data
.enter().append("p")
.call(myHoriz);
</script>
</body>
我应该添加,代码确实运行,四个段落添加到div中,每个段落的文本内容是数字1,2,3,7。所以我想至少select(),data(),enter()和append()位是工作。
Oh (edit), I should add, the code does run, in that I do get a document with four paragraphs added into the div, and the text contents of each paragraph are the numbers 1, 2, 3, 7. So I guess at least the select(), data(), enter(), and append() bits are working.
推荐答案
看起来你很困惑 horizon.metric 与 context.metric 。它是 context.metric
,它接受您定义的签名的函数。
It looks like you are confusing horizon.metric with context.metric. It is context.metric
that takes a function of the signature you're defining.
这篇关于最小cubism.js地平线图示例(TypeError:callback不是一个函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!