From 32e03133f5364ffb25b55d8b8dd34ed2962f392a Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sat, 10 Apr 2010 11:07:08 +0100 Subject: A chart class with multiple RRD data sources and an example of stacked chart --- jrrd.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'jrrd.js') diff --git a/jrrd.js b/jrrd.js index f811223..44fdb95 100644 --- a/jrrd.js +++ b/jrrd.js @@ -43,10 +43,15 @@ jrrd.RrdQuery = function(rrd) { this.rrd = rrd; }; -jrrd.RrdQuery.prototype.getData = function(startTime, endTime) { +jrrd.RrdQuery.prototype.getData = function(startTime, endTime, dsId) { var startTimestamp = startTime.getTime()/1000; var endTimestamp = endTime.getTime()/1000; + if(dsId == null) { + dsId = 0; + } + var ds = this.rrd.getDS(dsId); + var consolidationFunc = 'AVERAGE'; var lastUpdated = this.rrd.getLastUpdate(); @@ -74,18 +79,16 @@ jrrd.RrdQuery.prototype.getData = function(startTime, endTime) { startRow = rraRowCount - parseInt((lastUpdated - startTimestamp)/step); endRow = rraRowCount - parseInt((lastUpdated - endTimestamp)/step); - returnData = []; - for(var d=this.rrd.getNrDSs()-1; d>=0; d--) { - flotData = []; - timestamp = firstUpdated + (startRow - 1) * step; - for (var i=startRow; i<=endRow; i++) { - var val = bestRRA.getEl(i, d); - flotData.push([timestamp*1000.0, val]); - timestamp += step; - } - returnData.push({label: this.rrd.getDS(d).getName(), data: flotData}); + + flotData = []; + timestamp = firstUpdated + (startRow - 1) * step; + dsIndex = ds.getIdx(); + for (var i=startRow; i<=endRow; i++) { + var val = bestRRA.getEl(i, dsIndex); + flotData.push([timestamp*1000.0, val]); + timestamp += step; } - return returnData; + return {label: ds.getName(), data: flotData}; }; -- cgit v1.2.3-2-g168b