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_);
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));
}
--- /dev/null
+<html>
+ <head>
+ <title>numeric axis</title>
+ <!--[if IE]>
+ <script type="text/javascript" src="excanvas.js"></script>
+ <![endif]-->
+ <script type="text/javascript" src="../dygraph-combined.js"></script>
+ <script type="text/javascript" src="../dygraph.js"></script>
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
+ </head>
+ <body>
+ <p>CSV data source:</p>
+ <div id="g" style="width:600px; height:300px;"></div>
+
+ <p>GViz data source:</p>
+ <div id="gviz" style="width:600px; height:300px;"></div>
+
+ <script type="text/javascript">
+ g = new DateGraph(
+ document.getElementById("g"),
+ function() {
+ var ret = "X,Y1,Y2\n";
+ for (var i = 0; i < 100; i++) {
+ ret += i + "," + i + "," + (i * (100-i) * 100/(50*50)) + "\n";
+ }
+ return ret;
+ }, null,
+ {
+ xValueParser: function(x) { return parseFloat(x); },
+ xValueFormatter: function(x) { return x; },
+ xTicker: DateGraph.prototype.numericTicks
+ }
+ );
+
+ google.load('visualization', '1', {packages: ['linechart']});
+ function addGViz() {
+ data = new google.visualization.DataTable();
+ data.addColumn('number', 'X');
+ data.addColumn('number', 'Y1');
+ data.addColumn('number', 'Y2');
+ data.addRows(100);
+ for (var i = 0; i < 100; i++) {
+ data.setCell(i, 0, i);
+ data.setCell(i, 1, i);
+ data.setCell(i, 2, i * (100-i) * 100/(50*50));
+ }
+
+ new DateGraph.GVizChart(
+ document.getElementById('gviz')).draw(data,
+ {
+ xValueParser: function(x) { return parseFloat(x); },
+ xValueFormatter: function(x) { return x; },
+ xTicker: DateGraph.prototype.numericTicks
+ });
+ }
+
+ google.setOnLoadCallback(addGViz);
+ </script>
+ </body>
+</html>