From: Dan Vanderkam Date: Sat, 29 Aug 2009 19:59:32 +0000 (+0000) Subject: add support for numeric axes in gviz. fixes issue 27 X-Git-Tag: v1.0.0~894 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=d955e223be111db06e403e9e40cc5007270c0950;p=dygraphs.git add support for numeric axes in gviz. fixes issue 27 --- diff --git a/dygraph.js b/dygraph.js index be0dca1..f5b5d72 100644 --- a/dygraph.js +++ b/dygraph.js @@ -1136,7 +1136,7 @@ DateGraph.prototype.parseDataTable_ = function(data) { for (var i = 0; i < cols; i++) { labels.push(data.getColumnLabel(i)); } - labels.shift(); // a "date" parameter is assumed. + labels.shift(); // the x-axis parameter is assumed and unnamed. this.labels_ = labels; // regenerate automatic colors. this.setColors_(this.attrs_); @@ -1144,16 +1144,22 @@ DateGraph.prototype.parseDataTable_ = function(data) { MochiKit.Base.update(this.plotter_.options, this.renderOptions_); MochiKit.Base.update(this.layoutOptions_, this.attrs_); - // Assume column 1 is a date type for now. - if (data.getColumnType(0) != 'date') { - alert("only date type is support for column 1 of DataTable input."); + var indepType = data.getColumnType(0); + if (indepType != 'date' && indepType != 'number') { + // TODO(danvk): standardize error reporting. + alert("only 'date' and 'number' types are supported for column 1" + + "of DataTable input (Got '" + indepType + "')"); return null; } var ret = []; for (var i = 0; i < rows; i++) { var row = []; - row.push(data.getValue(i, 0).getTime()); + if (indepType == 'date') { + row.push(data.getValue(i, 0).getTime()); + } else { + row.push(data.getValue(i, 0)); + } for (var j = 1; j < cols; j++) { row.push(data.getValue(i, j)); } diff --git a/tests/numeric-axis.html b/tests/numeric-axis.html new file mode 100644 index 0000000..ad8d9e6 --- /dev/null +++ b/tests/numeric-axis.html @@ -0,0 +1,60 @@ + + + numeric axis + + + + + + +

CSV data source:

+
+ +

GViz data source:

+
+ + + +