2012-10-24 16 views
6

Tôi chỉ mới bắt đầu với cubism.jsLàm cách nào để thay đổi bước cho số liệu Cube?

Tách mã ví dụ xuống Tôi có thể hiển thị hai số liệu .. một tính (kpi1) - hàm ngẫu nhiên, một từ Cube (kpi2). Nó hoạt động hoàn hảo tại một bước bối cảnh của 1e4 ngay sau khi tôi thay đổi nó thành 1e3 tính toán một - ngẫu nhiên - cho thấy tốt ở độ phân giải 1s trong khi một từ Cube không hiển thị ở tất cả.

công trình này:

var context = cubism.context() 
    .serverDelay(0) 
    .clientDelay(0) 
    .step(1e4) 
    .size(960); 

này không:

var context = cubism.context() 
    .serverDelay(0) 
    .clientDelay(0) 
    .step(1e3) 
    .size(960); 

Tôi đang làm gì sai?

<!DOCTYPE html> 
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta charset="utf-8"> 

<title>Dashboard</title> 

</head><body><div id="body"> 


<div id="kpi1"></div> 
<div id="kpi2"></div> 


<script src="../d3.v2.js"></script> 
<script src="../cubism.v1.js"></script> 

<script>function random(name) { 
    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 += .2))); 
     values.push(value); 
    } 
    callback(null, values = values.slice((start - stop)/step)); 
    }, name); 
}</script> 

<script> 

var context = cubism.context() 
    .serverDelay(0) 
    .clientDelay(0) 
    .step(1e4) 
    .size(960); 

var foo = random("foo"); 
var cube = context.cube(); 

d3.select("#kpi1").call(function(div) { 

    div.selectAll(".horizon") 
     .data([foo]) 
    .enter().append("div") 
     .attr("class", "horizon") 
     .call(context.horizon()); 

}); 

d3.select("#kpi2").call(function(div) { 

    div.selectAll(".horizon") 
     .data([cube.metric("median(cube_compute(ms))")]) 
    .enter().append("div") 
     .attr("class", "horizon") 
     .call(context.horizon()); 

}); 

</script> 

</body></html> 

Trả lời

4

Cubism.js hỗ trợ bất cứ bước nào nhưng hệ thống backend Cube chỉ hỗ trợ tập hợp số liệu từ lưu trữ trên một trong năm bước sau:

1e4 or 10 seconds 
    6e4 or 1 minute 
    3e5 or 5 minutes 
    36e5 or 1 hour 
    864e5 or 1 day 

Nếu bạn đã sử dụng một bước mà nằm giữa hoặc dưới các giá trị này, Cube sẽ không thể tận dụng các precalculations được thực hiện ở các mức hỗ trợ thấp hơn và thấp nhất, sử dụng pyramidal reducers.

+0

Bạn có biết yếu tố nào của cải tiến hiệu suất này cung cấp không? – Renaud

Các vấn đề liên quan