[英]Unable to resize Cubism graph D3.js
I got the cubism code from the Cubism Demo . 我从“ 立体主义演示”中获得了立体主义代码。 The timeframe by default in the demo code is 4 hours.
演示代码中的默认时间范围是4小时。 I'm trying to reduce it to 15 min.
我正在尝试将其减少到15分钟。 I successfully modified the option to make it 15 min but the graph got shrinked.
我成功修改了选项,使其变为15分钟,但图形缩小了。
Here is the JavaScript code : 这是JavaScript代码:
var context = cubism.context()
.step(10000)
.size(1440); // Modified this to 90 to make it 15 min
d3.select("body").selectAll(".axis")
.data(["top", "bottom"])
.enter().append("div")
.attr("class", function(d) { return d + " axis"; })
.each(function(d) { d3.select(this).call(context.axis().ticks(12).orient(d)); });
d3.select("body").append("div")
.attr("class", "rule")
.call(context.rule());
d3.select("body").selectAll(".horizon")
.data(d3.range(1, 3).map(random))
.enter().insert("div", ".bottom")
.attr("class", "horizon")
.call(context.horizon().extent([-10, 10]));
context.on("focus", function(i) {
d3.selectAll(".value").style("right", i == null ? null : context.size() - i + "px");
});
// Replace this with context.graphite and graphite.metric!
function random(x) {
var value = 0,
values = [],
i = 0,
last;
return context.metric(function(start, stop, step, callback) {
start = +start, stop = +stop;
if (isNaN(last)) last = start;
while (last < stop) {
last += step;
value = Math.max(-10, Math.min(10, value + .8 * Math.random() - .4 + .2 * Math.cos(i += x * .02)));
values.push(value);
}
callback(null, values = values.slice((start - stop) / step));
}, x);
}
How to display 15 min or lower time frame in Cubism graph? 如何在立体主义图中显示15分钟或更短的时间范围?
Size option defines the number of values shown in the graph so 1440 values = 1440px width. 大小选项定义了图中显示的值的数量,因此1440个值= 1440px宽度。 According to the docs, step set the context step in milliseconds.
根据文档,step将上下文步设置为毫秒。 So, if you want to display 15min = 900000ms, in a graph that is 1440px wide you have to use a step that is 900000/1440 = 625.
因此,如果要显示15min = 900000ms,则在1440px宽的图形中,必须使用900000/1440 = 625的步长。
var context = cubism.context()
.step(625)
.size(1440);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.