我正在绘制一些我存储在每秒更新的主干集合中的指标。我没有看到在立体主义上绘制正确的指标。对于每个指标,我只得到一个指标(具有不正确的)值。我真的不知道如何调试这个。这是我的代码:
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);
}
这是我看到的绘制的屏幕截图,每个指标绘制相同的值(我验证的是不正确的数据)。