<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>
<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>
<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>
<script type="text/javascript" src="combined.js"></script>
</head>
<body>
-<div id="graphdiv" style="width:400px; height:300px;"></div>
+<div id="graphdiv"></div>
<script type="text/javascript">
- 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",
);
</script>
</body>
</html>
</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>
<body>
<div id="graphdiv" style="width:600px; height:300px;"></div>
<script type="text/javascript">
- 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
);
</script>
</body>
</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>
<body>
<div id="graphdiv" style="width:600px; height:300px;"></div>
<script type="text/javascript">
- g = new DateGraph(
+ g = new Dygraph(
document.getElementById("graphdiv"),
- "temperatures.csv", null,
+ "temperatures.csv",
{ rollPeriod: 7,
showRoller: true,
- valueRange: [25, 100]
}
);
</script>
</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>σ</i> = sqrt((<i>σ_1</i>^2 + <i>σ_2</i>^2 + ... + <i>σ_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>σ</i> = sqrt((<i>σ_1</i>^2 + <i>σ_2</i>^2 + ... + <i>σ_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>
></div>
<script type="text/javascript">
$ = document.getElementById;
-g = new DateGraph(
+g = new Dygraph(
$("graphdiv"),
"twonormals.csv",
- null,
{ rollPeriod: 7,
showRoller: true,
errorBars: true,
<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,
<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,
<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>
</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
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><center></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>