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 --- index.html | 73 +++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 20 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index 48bd6a1..e209be2 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,7 @@ + @@ -23,10 +24,12 @@ mode: 'x' }, series: { + stack: true, points: { show: false }, lines: { show: true, steps: false, + fill: 0.1, shadowSize: 0, lineWidth: 1 }, @@ -37,36 +40,66 @@ } }; - function drawChart(db, startTime, endTime) { - return db.getData(startTime, endTime) - .addCallback( - function(data) { - var plot = $.plot($('.container'), data, graphOptions); - }) - .addErrback( - function(failure) { - $('.container').text('error: ' + failure.message); - }); - } - - var db = new jrrd.RrdQueryRemote('data/localhost/load/load.rrd'); + var Chart = function(template) { + var self = this; - $(function() { - drawChart(db, new Date('7 April 2010 09:30:00'), - new Date('7 April 2010 15:00:00')); + this.template = template; + this.data = []; - $('.container').bind('plotclick', function(event, pos, item) { + this.template.bind('plotclick', function(event, pos, item) { if (item) { - console.log(['X: ' + new Date(item.datapoint[0]), 'Y: ' + item.datapoint[1]]); + console.log(['X: ' + new Date(item.datapoint[0]), + 'Y: ' + item.datapoint[1]]); } }); - $('.container').bind("plotselected", function(event, ranges) { + this.template.bind("plotselected", function(event, ranges) { var startTime = new Date(ranges.xaxis.from); var endTime = new Date(ranges.xaxis.to); - drawChart(db, startTime, endTime); + self.draw(startTime, endTime); console.log("You selected " + startTime + " to " + endTime); }); + }; + + Chart.prototype.addData = function(label, db) { + this.data.push([label, db]); + }; + + Chart.prototype.draw = function(startTime, endTime) { + var self = this; + + var results = []; + for(var i=0; i -- cgit v1.2.3-2-g168b