Update Dow Jones Industrial Average demo
[dygraphs.git] / docs / index.html
index 0c80ef4..b0aceb3 100644 (file)
@@ -27,7 +27,7 @@
     <a href="http://code.google.com/p/dygraphs/">code.google.com/p/dygraphs</a></p>
   </center>
 
-<p>The dygraphs JavaScript library produces produces interactive, zoomable charts of time series based on CSV files.</p>
+<p>The dygraphs JavaScript library produces produces interactive, zoomable charts of time series.</p>
 
 <h3>Features</h3>
 <ul>
@@ -38,6 +38,7 @@
   <li>Interactive zoom</li>
   <li>Adjustable averaging period</li>
   <li>Customizable click-through actions</li>
+  <li>Compatible with the Google Visualization API</li>
 </ul>
 
 <h3>Caveats</h3>
   g = new DateGraph(
           document.getElementById("demodiv"),
           function() {
+            var zp = function(x) { if (x < 10) return "0"+x; else return x; };
             var r = "date,parabola,line,another line,sine wave\n";
             for (var i=1; i<=31; i++) {
-            r += "200610" + i;
+            r += "200610" + zp(i);
             r += "," + 10*(i*(31-i));
             r += "," + 10*(8*i);
             r += "," + 10*(250 - 8*i);
@@ -86,7 +88,7 @@
 
 <h2>Usage</h2>
 
-<p>The DateGraph library depends on two other JS libraries: <a href="http://www.mochikit.com/">MochiKit</a> and <a href="http://www.liquidx.net/plotkit/">PlotKit</a>. Rather than tracking down copies of these libraries, I recommend using a packed version of dygraphs that combines all three libraries into a single JS file. Either grab this file from dygraph project's <a href="http://code.google.com/p/dygraphs/downloads/list">downloads</a> page or create it yourself by <a href="http://code.google.com/p/dygraphs/source/checkout">checking out</a> a copy of the code and running:
+<p>The dygraphs library depends on two other JS libraries: <a href="http://www.mochikit.com/">MochiKit</a> and <a href="http://www.liquidx.net/plotkit/">PlotKit</a>. Rather than tracking down copies of these libraries, I recommend using a packed version of dygraphs that combines all three libraries into a single JS file. Either grab this file from dygraph project's <a href="http://code.google.com/p/dygraphs/downloads/list">downloads</a> page or create it yourself by <a href="http://code.google.com/p/dygraphs/source/checkout">checking out</a> a copy of the code and running:
 
 <pre>./generate-combined.sh</pre>
 
 &lt;script type="text/javascript" src="combined.js"&gt;&lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;
-&lt;div id="graphdiv" style="width:400px; height:300px;"&gt;&lt;/div&gt;
+&lt;div id="graphdiv"&gt;&lt;/div&gt;
 &lt;script type="text/javascript"&gt;
-  g = new DateGraph(
+  g = new Dygraph(
         document.getElementById("graphdiv"),  // containing div
-        function() {                // function or path to CSV file.
-          return "20080507,75\n" +
-                 "20080508,70\n" +
-                 "20080509,80\n";
-        },
-        [ "Temperature" ],          // names of data series
-        {}                          // additional options (see below)
+        "Date,Temperature\n" +                // CSV or path to a CSV file.
+        "20080507,75\n" +
+        "20080508,70\n" +
+        "20080509,80\n",
       );
 &lt;/script&gt;
 &lt;/body&gt;
 &lt;/html&gt;
 </pre>
 </td><td valign=top>
-  <div id="graphdiv" style="width:400px; height:300px;"></div>
+  <div id="graphdiv"></div>
   <script type="text/javascript">
-    g = new DateGraph(
-          document.getElementById("graphdiv"),
-          function() {                          // function or path to CSV file.
-            return "20080507,75\n" +
-                   "20080508,70\n" +
-                   "20080509,80\n";
-          },
-          [ "Temperature" ],                    // names of data series
-          {}                                    // additional options
-        );
+    g = new Dygraph(
+        document.getElementById("graphdiv"),  // containing div
+        "Date,Temperature\n" +                // CSV or path to a CSV file.
+        "20080507,75\n" +
+        "20080508,70\n" +
+        "20080509,80\n"
+      );
   </script>
 </td></tr></table>
 
-<p>In order to keep this example self-contained, the second parameter is a function that returns CSV data. These lines <i>must</i> begin with a date in the form <i>YYYYMMDD</i>. In most applications, it makes more sense to include a CSV file instead. If the second parameter to the constructor is a string, it will be interpreted as the path to a CSV file. The DateGraph will perform an XMLHttpRequest to retrieve this file and display the data when it becomes available. Make sure your CSV file is readable and serving from a place that understands XMLHttpRequest's! In particular, you cannot specify a CSV file using <code>"file:///"</code>. Here's an example: (data from <a href="http://www.wunderground.com/history/airport/KNUQ/2007/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2007&req_city=NA&req_state=NA&req_statename=NA">Weather Underground</a>)</p>
+<p>In order to keep this example self-contained, the second parameter is a function that returns CSV data. These lines <i>must</i> begin with a date in the form <i>YYYYMMDD</i>. In most applications, it makes more sense to include a CSV file instead. If the second parameter to the constructor is a string, it will be interpreted as the path to a CSV file. The Dygraph will perform an XMLHttpRequest to retrieve this file and display the data when it becomes available. Make sure your CSV file is readable and serving from a place that understands XMLHttpRequest's! In particular, you cannot specify a CSV file using <code>"file:///"</code>. Here's an example: (data from <a href="http://www.wunderground.com/history/airport/KNUQ/2007/1/1/CustomHistory.html?dayend=31&monthend=12&yearend=2007&req_city=NA&req_state=NA&req_statename=NA">Weather Underground</a>)</p>
 
 <table>
   <tr><th>HTML</th>
 &lt;body&gt;
 &lt;div id="graphdiv" style="width:600px; height:300px;"&gt;&lt;/div&gt;
 &lt;script type="text/javascript"&gt;
-  g = new DateGraph(
+  g = new Dygraph(
         document.getElementById("graphdiv"),
         "temperatures.csv",  // path to CSV file
-        null,                // labels in top line of CSV file
-        {}
+        {}                   // additional options
       );
 &lt;/script&gt;
 &lt;/body&gt;
 </td><td valign=top>
   <div id="graphdiv2" style="width:600px; height:300px;"></div>
   <script type="text/javascript">
-    g2 = new DateGraph(
+    g2 = new Dygraph(
           document.getElementById("graphdiv2"),
-          "temperatures.csv", null, {}
+          "temperatures.csv", {}
         );
   </script>
 </td></tr></table>
 <p>Click <a href="temperatures.csv">here</a> to view the <code>temperatures.csv</code> file. There are a few things to note here:</p>
 
 <ul>
-  <li>Because the third parameter to the DateGraph constructor was <code>null</code>, the labels were taken from the first line of the data instead. The first line of <code>temperatures.csv</code> is <code>Date,High,Low</code>.</li>
-  <li>DateGraph automatically chose two different, easily-distinguishable colors for the two data series.</li>
+  <li>The Dygraph sent off an XHR to get the temperatures.csv file.</li>
+  <li>The labels were taken from the first line of <code>temperatures.csv</code>, which is <code>Date,High,Low</code>.</li>
+  <li>The Dygraph automatically chose two different, easily-distinguishable colors for the two data series.</li>
   <li>The labels on the x-axis have switched from days to months. If you zoom in, they'll switch to weeks and then days.</li>
-  <li>Some heuristics are used to determine a good vertical range for the data. The idea is to make all the data visible and have human-friendly values on the axis (i.e. 200 instead of 193.4). Generally this works well, but in this case the vertical range is way too large.</li>
+  <li>Some heuristics are used to determine a good vertical range for the data. The idea is to make all the data visible and have human-friendly values on the axis (i.e. 200 instead of 193.4). Generally this works well.</li>
   <li>The data is very spiky. A moving average would be easier to interpret.</li>
 </ul>
 
-<p>These last two problems can be fixed by specifying the appropriate options in the fourth parameter to the DateGraph constructor. To set the number of days for a moving average, use the <b>rollPeriod</b> option. To set the range of the y-axis, use the <b>valueRange</b> option. Here's how it's done:</p>
+<p>This problem can be fixed by specifying the appropriate options in the "additional options" parameter to the Dygraph constructor. To set the number of days for a moving average, use the <b>rollPeriod</b> option. Here's how it's done:</p>
 
 <table>
   <tr><th>HTML</th>
 &lt;body&gt;
 &lt;div id="graphdiv" style="width:600px; height:300px;"&gt;&lt;/div&gt;
 &lt;script type="text/javascript"&gt;
-  g = new DateGraph(
+  g = new Dygraph(
         document.getElementById("graphdiv"),
-        "temperatures.csv", null,
+        "temperatures.csv",
         { rollPeriod: 7,
           showRoller: true,
-          valueRange: [25, 100]
         }
       );
 &lt;/script&gt;
 </td><td valign=top>
   <div id="graphdiv3" style="width:600px; height:300px;"></div>
   <script type="text/javascript">
-    g3 = new DateGraph(
+    g3 = new Dygraph(
           document.getElementById("graphdiv3"),
-          "temperatures.csv", null,
+          "temperatures.csv",
           { rollPeriod: 7,
             showRoller: true,
-            valueRange: [25, 100]
           }
         );
   </script>
 <p>A rolling average can be set using the text box in the lower left-hand corner of the graph (the showRoller attribute is what makes this appear).</p>
 
 <h2>Error Bars</h2>
-<p>Another significant feature of the dygraphs library is the ability to display error bars around data series. One standard deviation must be specified for each data point. A +/-<i>n</i> sigma band will be drawn around the data series at that point. If a moving average is being displayed, DateGraph will compute the standard deviation of the average at each point. (i.e. <i>&sigma;</i> = sqrt((<i>&sigma;_1</i>^2 + <i>&sigma;_2</i>^2 + ... + <i>&sigma;_n</i>^2)/<i>n</i>))</p>
+<p>Another significant feature of the dygraphs library is the ability to display error bars around data series. One standard deviation must be specified for each data point. A +/-<i>n</i> sigma band will be drawn around the data series at that point. If a moving average is being displayed, dygraphs will compute the standard deviation of the average at each point. (i.e. <i>&sigma;</i> = sqrt((<i>&sigma;_1</i>^2 + <i>&sigma;_2</i>^2 + ... + <i>&sigma;_n</i>^2)/<i>n</i>))</p>
 
 <p>Here's a demonstration. There are two data series. One is <code>N(100,10)</code> with a standard deviation of 10 specified at each point. The other is <code>N(80,20)</code> with a standard deviation of 20 specified at each point. The CSV file was generated using Octave and can be viewed <a href="twonormals.csv">here</a>.</p>
 
  &gt;&lt;/div&gt;
 &lt;script type="text/javascript"&gt;
 $ = document.getElementById;
-g = new DateGraph(
+g = new Dygraph(
   $("graphdiv"),
   "twonormals.csv",
-  null,
   { rollPeriod: 7,
     showRoller: true,
     errorBars: true,
@@ -263,10 +256,9 @@ g = new DateGraph(
   <div id="graphdiv4" style="width:800px; height:400px;"></div>
   <script type="text/javascript">
 $ = document.getElementById;
-new DateGraph(
+new Dygraph(
   document.getElementById("graphdiv4"),
   "twonormals.csv",
-  null,
   { rollPeriod: 14,
     showRoller: true,
     errorBars: true,
@@ -291,10 +283,9 @@ new DateGraph(
 <div id=dow_chart style="width:1000px; height:400px;"></div>
 <script type="text/javascript">
   // From http://www.econstats.com/eqty/eq_d_mi_3.csv
-  dow = new DateGraph(
+  dow = new Dygraph(
     document.getElementById('dow_chart'),
     "dow.txt",
-    null,
     {
       showRoller: true,
       customBars: true,
@@ -305,7 +296,7 @@ new DateGraph(
 
 
 <h2>Other Options</h2>
-<p>These are the options that can be passed in through the fourth parameter of the DateGraph constructor.</p>
+<p>These are the options that can be passed in through the optional third parameter of the Dygraph constructor.</p>
 
 <table class=thinborder width=1000>
   <tr><th>Name</th><th>Sample Value</th><th>Description</th></tr>
@@ -394,7 +385,7 @@ new DateGraph(
   </tr>
 </table>
 
-<p>Any options you specify also get passed on to PlotKit's <a href="http://media.liquidx.net/js/plotkit-doc/PlotKit.Renderer.html">Renderer</a> class. DateGraph will override some of these (e.g. strokeColor), but others may be useful. The <code>padding</code> property is an example of this.</p>
+<p>Any options you specify also get passed on to PlotKit's <a href="http://media.liquidx.net/js/plotkit-doc/PlotKit.Renderer.html">Renderer</a> class. dygraphs will override some of these (e.g. strokeColor), but others may be useful. The <code>padding</code> property is an example of this.</p>
 
 <h2>Common Gotchas</h2>
 <p>Here are a few problems that I've frequently run into while using the
@@ -407,22 +398,15 @@ dygraphs library.</p>
     href="http://www.getfirebug.com/">Firebug</a>.</li>
 
   <li>Make sure your CSV files are in the correct format. They must be of the
-  form <code>YYYYMMDD,series1,series2,...</code>. If you're specifying the
-  names of each data series in the CSV file itself, make sure that you pass
-  <code>null</code> as the third parameter to the DateGraph constructor to let
-  the library know that. And if you set the <code>errorBars</code> property,
-  make sure you alternate data series and standard deviations.</li>
+  form <code>YYYYMMDD,series1,series2,...</code>. And if you set the
+  <code>errorBars</code> property, make sure you alternate data series and
+  standard deviations.</li>
 
   <li>dygraphs are not happy when placed inside a <code>&lt;center&gt;</code>
   tag. This applies to the CSS <code>text-align</code> property as well. If you
-  want to center a DateGraph, put it inside a table with "align=center"
+  want to center a Dygraph, put it inside a table with "align=center"
   set.</li>
 
-  <li>If you specify the <code>colors</code> property or name the data series
-  using the third parameter of the DateGraph constructor, make sure the number
-  of data series agree in all places: <code>colors</code>, third parameter and
-  in each line of the CSV file itself.</li>
-
   <li>Don't set the <code>dateWindow</code> property to a date. It expects
   milliseconds since epoch, which can be obtained from a JavaScript Date
   object's valueOf method.</li>