我正在绘制一些存储在骨干集合中的指标,这些指标每秒都会更新。我没有看到在立体主义上绘制的正确指标。对于每个指标,我只得到一个绘制的指标(带有不正确的)值。我真的不知道如何调试它。这是我的代码:
var models = dataSet.models;
//aggregate 'metrics'. Each component has a 'metric' which contains its stats over time
for(model in models){
var attributes = models[model].attributes;
var metricData = metricCache.get(models[model].id);
var metrics = metricData['attributes']['metrics'];
if(!attributes['name'] || attributes['type']== "FLOW" || attributes['type'] == "SERVER"){
continue;
}
if(attributes['name'] == null){
continue;
}
var name = attributes['name'];
var type = attributes['type'];
var metName = name;
/* GETTING METRIC. Using js closure to pass correct values to metric call */
if(metricData != null){
//var curContext = getMetric(metName, metrics);
var curContext = (function(val1, val2){
return getMetric(val1, val2);
})(metName,metrics);
}
statsList.push(curContext);
}
'getMetric' 采用指标的名称和 'metrics',这是一个对象数组,其中每个对象都有一个时间戳和一个值。我只是试图在水平图表上绘制每个值及其相应的时间戳。这是我的“getMetric”代码。
function getMetric(name, metricData){
var format = d3.time.format("%I-%M-%S");
return context.metric(function(start, stop, step, callback){
var statValues = [];
var lookup = {},
i = start.getTime();
//console.log('startTime', i);
var curStat = null;
for(stat in metricData){
curStat = metricData[stat];
curStat.value = +curStat.value;
var curDate = new Date(curStat.timestamp);
curDate = format(curDate);
lookup[curDate] = curStat;
}
var lastValue;
while((i+=step) < stop){
var key = format(new Date(i));
var curVal = key in lookup ? lookup[key].value : NaN;
console.log(name,curVal);
statValues.push(curVal);
}
//console.log(statValues);
callback(null,statValues);
}, name);
}
这是我看到的绘制的屏幕截图,每个度量都绘制相同的值(我验证的是不正确的数据)。