UNPKG

24.7 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>Dygraphs — tutorial</title>
7
8 <link rel="stylesheet" type="text/css" href=".jslibs/bootstrap.min.css" />
9 <link rel="stylesheet" type="text/css" href="dist/dygraph.css" />
10 <link rel="stylesheet" type="text/css" href="common/vextlnk.css" />
11 <link rel="stylesheet" type="text/css" href="site.css" />
12
13 <script type="text/javascript" src=".jslibs/jquery.min.js"></script>
14 <script type="text/javascript" src=".jslibs/bootstrap.min.js"></script>
15 <script type="text/javascript" src="dist/dygraph.js"></script>
16 </head>
17 <body>
18 <nav id="header" class="navbar navbar-default navbar-fixed-top">
19 <div class="container-fluid">
20 <div class="navbar-header">
21 <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-responsive-collapse" aria-expanded="false">
22 <span class="sr-only">Toggle navigation</span>
23 <span class="icon-bar"></span>
24 <span class="icon-bar"></span>
25 <span class="icon-bar"></span>
26 </button>
27 <a class="navbar-brand" href="/">dygraphs</a>
28 </div><!-- /navbar-header -->
29 <div class="collapse navbar-collapse" id="navbar-responsive-collapse">
30
31 <!-- TODO(danvk): fill in relevant links here -->
32 <ul class="nav navbar-nav">
33 <li class="dropdown">
34 <a class="dropdown-toggle" id="drop3" role="button" data-toggle="dropdown" href="#">Documentation<b class="caret"></b></a>
35 <ul id="menu0" class="dropdown-menu" role="menu" aria-labelledby="drop3">
36 <li role="presentation"><a role="menuitem" tabindex="-1" href="tutorial.html">Tutorial</a></li>
37 <li role="presentation"><a role="menuitem" tabindex="-1" href="options.html">Options Reference</a></li>
38 <li role="presentation"><a role="menuitem" tabindex="-1" href="jsdoc/symbols/Dygraph.html">API Reference</a></li>
39 <li role="presentation"><a role="menuitem" tabindex="-1" href="data.html">Data Format</a></li>
40 <li role="presentation"><a role="menuitem" tabindex="-1" href="annotations.html">Annotations</a></li>
41 <li role="presentation"><a role="menuitem" tabindex="-1" href="css.html">CSS Reference</a></li>
42 <li role="presentation"><a role="menuitem" tabindex="-1" href="versions.html">Version History</a></li>
43 <li role="separator" class="divider"></li>
44 <li role="presentation"><a role="menuitem" tabindex="-1" href="ie.html">Notes on Internet Explorer</a></li>
45 </ul>
46 </li>
47 <li class="dropdown">
48 <a class="dropdown-toggle" id="drop4" role="button" data-toggle="dropdown" href="#">Examples<b class="caret"></b></a>
49 <ul id="menu1" class="dropdown-menu" role="menu" aria-labelledby="drop4">
50 <li role="presentation"><a role="menuitem" tabindex="-1" href="gallery/">Demo Gallery</a></li>
51 <li role="presentation"><a role="menuitem" tabindex="-1" href="users.html">List of Users</a></li>
52 <li role="separator" class="divider"></li>
53 <li role="presentation"><a role="menuitem" tabindex="-1" href="tests/">Test Cases</a></li>
54 <li role="separator" class="divider"></li>
55 <li role="presentation"><a role="menuitem" tabindex="-1" href="https://dygraphs.com/fiddle/">Play</a></li>
56 </ul>
57 </li>
58 <li><a class="xnavbar-link" href="download.html">Download</a></li>
59 <li class="dropdown">
60 <a class="dropdown-toggle" id="drop7" role="button" data-toggle="dropdown" href="#">Community <b class="caret"></b></a>
61 <ul id="menu4" class="dropdown-menu" role="menu" aria-labelledby="drop7">
62 <li role="presentation"><a role="menuitem" tabindex="-1" href="http://blog.dygraphs.com/">Blog</a></li>
63 <li role="presentation"><a role="menuitem" tabindex="-1" href="https://stackoverflow.com/questions/ask?tags=dygraphs+javascript">Ask a Question</a></li>
64 <li role="presentation"><a role="menuitem" tabindex="-1" href="https://stackoverflow.com/questions/tagged/dygraphs">Stack Overflow</a></li>
65 <li role="presentation"><a role="menuitem" tabindex="-1" href="https://groups.google.com/g/dygraphs-users">Mailing List</a></li>
66 </ul>
67 </li>
68 <li class="dropdown">
69 <a class="dropdown-toggle" id="drop6" role="button" data-toggle="dropdown" href="#">Contribute <b class="caret"></b></a>
70 <ul id="menu3" class="dropdown-menu" role="menu" aria-labelledby="drop6">
71 <li role="presentation"><a role="menuitem" tabindex="-1" href="changes.html">Contributors Guide</a></li>
72 <li role="presentation"><a role="menuitem" tabindex="-1" href="https://github.com/danvk/dygraphs">Source (Github)</a></li>
73 <li role="presentation"><a role="menuitem" tabindex="-1" href="https://github.com/danvk/dygraphs/issues">Issue Tracker</a></li>
74 <li role="presentation"><a role="menuitem" tabindex="-1" href="https://github.com/danvk/dygraphs/issues/new">Report a Bug</a></li>
75 </ul>
76 </li>
77 </ul><!-- /navbar-nav -->
78
79 </div><!-- /navbar-responsive-collapse -->
80 </div><!-- container-fluid -->
81 </nav>
82
83 <div class="container" id="main">
84 <div class="row">
85 <div class="col-lg-12">
86<p>To use dygraphs, include the <code><a href="download.html">dygraph.js</a></code> JavaScript file
87and <code>dygraph.css</code> CSS file. Then instantiate a <code>Dygraph</code> object.</p>
88
89<p>Here's a basic example to get things started:</p>
90
91<div class="example" style="clear:both;">
92 <div class="codeblock" style="float:left;width:400px;">
93 <h3 style="text-align:center">HTML</h3>
94 <pre>
95&lt;html&gt;&lt;head&gt;
96&lt;script type="text/javascript"
97 src="dygraph.js"&gt;&lt;/script&gt;
98&lt;link rel="stylesheet" type="text/css"
99 src="dygraph.css" /&gt;
100&lt;/head&gt;&lt;body&gt;
101&lt;div id="graphdiv"&gt;&lt;/div&gt;
102&lt;script type="text/javascript"&gt;
103Dygraph.onDOMready(function onDOMready() {
104 g = new Dygraph(
105
106 // containing div
107 document.getElementById("graphdiv"),
108
109 // CSV or path to a CSV file.
110 "Date,Temperature\n" +
111 "2008-05-07,75\n" +
112 "2008-05-08,70\n" +
113 "2008-05-09,80\n"
114
115 );
116});
117&lt;/script&gt;
118&lt;/body&gt;&lt;/html&gt;
119</pre>
120 </div>
121 <div class="codeoutput" style="float:left;">
122 <h3 style="text-align:center">OUTPUT</h3>
123 <div id="graphdiv"></div>
124 <script type="text/javascript"><!--//--><![CDATA[//><!--
125 Dygraph.onDOMready(function onDOMready() {
126 g = new Dygraph(
127 // containing div
128 document.getElementById("graphdiv"),
129
130 // CSV or path to a CSV file.
131 "Date,Temperature\n" +
132 "2008-05-07,75\n" +
133 "2008-05-08,70\n" +
134 "2008-05-09,80\n"
135 );
136 });
137 //--><!]]></script>
138 </div>
139</div>
140
141<p style="clear:both">In order to keep this example self-contained,
142 the second parameter is raw CSV data. You can use your favourite
143 “defer until DOM is ready” method (e.g. <a
144 href="http://api.prototypejs.org/dom/document/observe/index.html">Prototype</a> or <a
145 href="https://api.jquery.com/ready/">jQuery</a>); dygraphs includes a
146 small self-contained one that can be used if nothing else is available.
147 The dygraphs library parses this data (including column headers),
148 resizes its container to a reasonable default,
149 calculates appropriate axis ranges and tick marks and draws the graph.
150 <strong>Make sure the container does <em>not</em> have any padding.</strong>
151</p>
152
153<p>In most applications, it makes more sense to include a CSV file instead.
154 If the second parameter to the constructor doesn't contain a newline,
155 it will be interpreted as the path to a CSV file.
156 The Dygraph will perform an XMLHttpRequest to retrieve this file
157 and display the data when it becomes available.
158 Make sure your CSV file is readable and serving from a place that
159 understands <tt>XMLHttpRequest</tt>s! In particular, you cannot
160 specify a CSV file using <code>"file:///"</code>. Here's an example:
161 (data from <a href="http://www.wunderground.com/history/airport/KNUQ/2007/1/1/CustomHistory.html?dayend=31&amp;monthend=12&amp;yearend=2007&amp;req_city=NA&amp;req_state=NA&amp;req_statename=NA">Weather Underground</a>)
162</p>
163
164<div class="example" style="clear:both;">
165 <div class="codeblock" style="float:left;width:400px;">
166 <h3 style="text-align:center">HTML</h3>
167<pre>
168&lt;html&gt;&lt;head&gt;
169&lt;script type="text/javascript"
170 src="dygraph.js"&gt;&lt;/script&gt;
171&lt;link rel="stylesheet" type="text/css"
172 src="dygraph.css" /&gt;
173&lt;/head&gt;&lt;body&gt;
174&lt;div id="graphdiv2"
175 style="width:500px; height:300px;"&gt;&lt;/div&gt;
176&lt;script type="text/javascript"&gt;
177Dygraph.onDOMready(function onDOMready() {
178 g2 = new Dygraph(
179 document.getElementById("graphdiv2"),
180 "temperatures.csv", // path to CSV file
181 {} // options
182 );
183});
184&lt;/script&gt;
185&lt;/body&gt;&lt;/html&gt;
186</pre>
187 </div>
188 <div class="codeoutput" style="float:left;">
189 <h3 style="text-align:center">OUTPUT</h3>
190 <div id="graphdiv2" style="width:500px; height:300px;"></div>
191 <script type="text/javascript"><!--//--><![CDATA[//><!--
192 Dygraph.onDOMready(function onDOMready() {
193 g2 = new Dygraph(
194 document.getElementById("graphdiv2"),
195 "temperatures.csv",
196 {}
197 );
198 });
199 //--><!]]></script>
200 </div>
201</div>
202
203<p style="clear:both;">The file used is <code><a href="temperatures.csv">temperatures.csv</a></code>.</p>
204
205<p>There are a few things to note here:</p>
206
207<ul>
208 <li>The Dygraph sent off an XHR to get the temperatures.csv file.</li>
209 <li>The labels were taken from the first line of <code>temperatures.csv</code>, which is <code>Date,High,Low</code>. Make sure they are unique!</li>
210 <li>The Dygraph automatically chose two different, easily-distinguishable colors for the two data series.</li>
211 <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>
212 <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>
213 <li>The data is very spiky. A moving average would be easier to interpret.</li>
214</ul>
215
216<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 <code>rollPeriod</code> option. Here’s how it’s done:</p>
217
218<div class="example" style="clear:both;">
219 <div class="codeblock" style="float:left;width:400px;">
220 <h3 style="text-align:center">HTML</h3>
221<pre>
222&lt;html&gt;&lt;head&gt;
223&lt;script type="text/javascript"
224 src="dygraph.js"&gt;&lt;/script&gt;
225&lt;link rel="stylesheet" type="text/css"
226 src="dygraph.css" /&gt;
227&lt;/head&gt;&lt;body&gt;
228&lt;div id="graphdiv3"
229 style="width:500px; height:300px;"&gt;&lt;/div&gt;
230&lt;script type="text/javascript"&gt;
231Dygraph.onDOMready(function onDOMready() {
232 g3 = new Dygraph(
233 document.getElementById("graphdiv3"),
234 "temperatures.csv",
235 {
236 rollPeriod: 7,
237 showRoller: true
238 }
239 );
240});
241&lt;/script&gt;
242&lt;/body&gt;&lt;/html&gt;
243</pre>
244 </div>
245 <div class="codeoutput" style="float:left;">
246 <h3 style="text-align:center">OUTPUT</h3>
247 <div id="graphdiv3" style="width:500px; height:300px;"></div>
248 <script type="text/javascript"><!--//--><![CDATA[//><!--
249 Dygraph.onDOMready(function onDOMready() {
250 g3 = new Dygraph(
251 document.getElementById("graphdiv3"),
252 "temperatures.csv",
253 {
254 rollPeriod: 7,
255 showRoller: true
256 }
257 );
258 });
259 //--><!]]></script>
260 </div>
261</div>
262
263<p style="clear:both;">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). Also note that we've explicitly set the size of the chart div.</p>
264
265<h2>Bands</h2>
266
267<p>Another significant feature of the dygraphs library is the ability to
268 display high/low bands around data series. One standard deviation must
269 be specified for each data point. A <em>±n</em> sigma band will be
270 drawn around the data series at that point. If a moving average is
271 being displayed, dygraphs will compute the standard deviation of the
272 average at each point. I.E. <em>σ = sqrt( (σ<sub>1<sup>2</sup></sub> +
273 σ<sub>2<sup>2</sup></sub> + ... + σ<sub>n<sup>2</sup></sub>) / n )</em></p>
274
275<p>Here's a demonstration. There are two data series. One is
276 <code>N(100,10)</code> with a standard deviation of 10 specified at
277 each point. The other is <code>N(80,20)</code> with a standard
278 deviation of 20 specified at each point. The CSV file was generated
279 using Octave and can be viewed at <a href="twonormals.csv">twonormals.csv</a>.</p>
280
281<div class="example" style="clear:both;">
282 <div class="codeblock" style="float:left;width:400px;">
283 <h3 style="text-align:center">HTML</h3>
284<pre>
285&lt;html&gt;&lt;head&gt;
286&lt;script type="text/javascript"
287 src="dygraph.js"&gt;&lt;/script&gt;
288&lt;link rel="stylesheet" type="text/css"
289 src="dygraph.css" /&gt;
290&lt;/head&gt;&lt;body&gt;
291&lt;div id="graphdiv4"
292 style="width:480px; height:320px;"&gt;&lt;/div&gt;
293&lt;script type="text/javascript"&gt;
294Dygraph.onDOMready(function onDOMready() {
295 g4 = new Dygraph(
296 document.getElementById("graphdiv4"),
297 "twonormals.csv",
298 {
299 rollPeriod: 7,
300 showRoller: true,
301 errorBars: true,
302 valueRange: [50,125]
303 }
304 );
305});
306&lt;/script&gt;
307&lt;/body&gt;&lt;/html&gt;
308</pre>
309</div>
310<div class="codeoutput" style="float:left;">
311 <h3 style="text-align:center">OUTPUT</h3>
312 <div id="graphdiv4" style="width:480px; height:320px;"></div>
313 <script type="text/javascript"><!--//--><![CDATA[//><!--
314 Dygraph.onDOMready(function onDOMready() {
315 g4 = new Dygraph(
316 document.getElementById("graphdiv4"),
317 "twonormals.csv",
318 {
319 rollPeriod: 7,
320 showRoller: true,
321 errorBars: true,
322 valueRange: [50,125]
323 }
324 );
325 });
326 //--><!]]></script>
327</div>
328</div>
329
330<p style="clear:both;">Things to note here:</p>
331
332<ul>
333<li>The option is named <tt>errorBars</tt> for historical reasons.</li>
334<li>The <strong>errorBars</strong> option affects both the
335 interpretation of the CSV file and the display of the graph. When
336 <strong>errorBars</strong> is set to true, each line is interpreted as
337 <em>YYYY-MM-DD</em>, <em>A</em>, <em>sigma_A</em>, <em>B</em>,
338 <em>sigma_B</em>, …</li>
339<li>The first line of the CSV file doesn’t mention the extra columns.
340 In this case, it’s just "Date,Series1,Series2". (Which breaks the
341 CSV file format. This is an unfortunate historic accident.)</li>
342<li>The averaging visibly affects the high/low bands. This is most clear
343 if you crank up the rolling period to something like 100 days. For the
344 earliest dates, there won’t be 100 data points to average so the
345 signal will be noisier. The high/low bands get smaller like sqrt(N)
346 going forward in time until there’s a full 100 points to average.</li>
347<li>The high/low bands are partially transparent. This can be seen when
348 they overlap one another.</li>
349</ul>
350
351<h2 id="gviz">GViz Data</h2>
352
353<p>The <a
354 href="https://developers.google.com/chart/interactive/docs/reference">Google
355 Visualization API</a> provides a standard interface for describing data.
356Once you've specified your data using this API, you can plug in any
357GViz-compatible visualization. dygraphs is such a visualization. In
358particular, it can be used as a drop-in replacement for the
359AnnotatedTimeline visualization used on Google Finance and other sites. To
360see how this works, check out the <a href="tests/annotation-gviz.html">gviz
361annotation demo<b
362 title="WARNING: accesses external resources (Google jsapi)"></b>.</a></p>
363
364<p>Here is another demonstration of
365<a href="tests/gviz.html">how to use dygraphs a GViz visualization<b
366 title="WARNING: accesses external resources (Google jsapi)"></b></a>.
367</p>
368
369<h2 id="baseball">Charting Fractions</h2>
370
371<p>Situations often arise where you want to plot fractions, e.g. the fraction of respondents in a poll who said they'd vote for candidate X or the number of hits divided by at bats (baseball's batting average). Fractions require special treatment for two main reasons:</p>
372
373<ul>
374 <li>The average of <code>a1/b1</code> and <code>a2/b2</code> is <code>(a1+a2)/(b1+b2)</code>, not <code>(a1/b1 + a2/b2)/2</code>.</li>
375 <li>The normal approximation is not always applicable and more sophisticated confidence intervals (e.g. the <a href="https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval">Wilson confidence interval</a>) must be employed to avoid ratios that exceed 100% or go below 0%.</li>
376</ul>
377
378<p>Fortunately, dygraphs handles both of these for you! Here's a chart and the command that generated it:</p>
379
380<div style="width:750px; text-align:center; font-weight: bold; font-size: 125%;">Batting Average for Ichiro Suzuki vs. Mariners (2004)</div>
381<div id="baseballdiv" style="width:750px; height:300px;"></div>
382<script type="text/javascript"><!--//--><![CDATA[//><!--
383Dygraph.onDOMready(function onDOMready() {
384 new Dygraph(
385 document.getElementById("baseballdiv"),
386 "suzuki-mariners.txt",
387 {
388 fractions: true,
389 errorBars: true,
390 showRoller: true,
391 rollPeriod: 15
392 }
393 );
394});
395//--><!]]></script>
396
397<b>Code:</b>
398<pre>
399new Dygraph(
400 document.getElementById("baseballdiv"),
401 "suzuki-mariners.txt",
402 {
403 fractions: true,
404 errorBars: true,
405 showRoller: true,
406 rollPeriod: 15
407 }
408);
409</pre>
410
411<p>The <code>fractions</code> option indicates that the values in each column should be parsed as fractions (e.g. "1/2" instead of "0.5"). The <code>errorBars</code> option indicates that we'd like to see a confidence interval around each data point. By default, when <code>fractions</code> is set, you get a Wilson confidence interval. If you look carefully at the chart, you can see that the high/low bands are asymmetric.</p>
412
413<p>A couple things to notice about this chart:</p>
414
415<ul>
416 <li>The high/low bands for Ichiro's batting average are larger than for the Mariners', since he has far fewer at bats than his team.</li>
417 <li>dygraphs makes it easy to see "batting average over the last 30 games". This is ordinarily quite difficult to compute. It makes it clear where the "hot" and "cold" part of Suzuki's season were.</li>
418 <li>If you set the averaging period to something large, like 200, you'll see the team's and player's batting average through that game. The final number is the overall batting average for the season.</li>
419 <li>Where the high/low bands do not overlap, we can say with 95% confidence that the series differ. There is a better than 95% chance that Ichiro was a better hitter than his team as a whole in 2004, the year he won the batting title.</li>
420</ul>
421
422<h2 id="stock">One last demo</h2>
423
424<p>This chart shows monthly closes of the Dow Jones Industrial Average, both in nominal and real (i.e. adjusted for inflation) dollars. The shaded areas show its monthly high and low. CPI values with a base from 1982-84 are used to adjust for inflation.</p>
425
426<div id="dow_chart" style="width:750px; height:350px;"></div>
427<p><b>Display: </b>
428<input type=checkbox id=0 onClick="stockchange(this)" checked>
429<label for="0"> Nominal</label>
430<input type=checkbox id=1 onClick="stockchange(this)" checked>
431<label for="1"> Real</label>
432<input type=checkbox id=ann onClick="annotationschange(this)" checked>
433<label for="ann"> Annotations</label>
434</p>
435
436<script type="text/javascript"><!--//--><![CDATA[//><!--
437Dygraph.onDOMready(function onDOMready() {
438 stock_annotations = [
439 {
440 series: "Real",
441 x: "1929-08-15",
442 shortText: "A",
443 text: "1929 Stock Market Peak",
444 cssClass: 'tutannotation'
445 },
446 {
447 series: "Nominal",
448 x: "1987-08-15",
449 shortText: "B",
450 text: "1987 Crash",
451 cssClass: 'tutannotation'
452 },
453 {
454 series: "Nominal",
455 x: "1999-12-15",
456 shortText: "C",
457 text: "1999 (.com) Peak",
458 cssClass: 'tutannotation'
459 },
460 {
461 series: "Nominal",
462 x: "2007-10-15",
463 shortText: "D",
464 text: "All-Time Market Peak",
465 cssClass: 'tutannotation'
466 }
467 ];
468
469// From http://www.econstats.com/eqty/eq_d_mi_3.csv
470 stockchart = new Dygraph(
471 document.getElementById('dow_chart'),
472 "dow.txt",
473 {
474 showRoller: true,
475 customBars: true,
476 labelsKMB: true,
477 drawCallback: function(g, is_initial) {
478 if (!is_initial) return;
479 g.setAnnotations( stock_annotations );
480 }
481 }
482 );
483});
484
485 function stockchange(el) {
486 stockchart.setVisibility(el.id, el.checked);
487 }
488
489 function annotationschange(el) {
490 if (el.checked) {
491 stockchart.setAnnotations(stock_annotations);
492 } else {
493 stockchart.setAnnotations([]);
494 }
495 }
496//--><!]]></script>
497<!--
498
499Here is a script to regenerate the Dow Jones plot:
500
501# Get unadjusted DJIA data in a nice format:
502curl -O http://www.econstats.com/eqty/eq_d_mi_3.csv
503sed '1,17d' eq_d_mi_3.csv | cut -d, -f1,6 | perl -pe 's/(\d{4}-\d\d)-\d\d/$1/g' | perl -pe 's/, */\t/' | grep -v 'na' | perl -ne 'chomp; ($m,$v) = split/\t/; $close{$m} = $v; if ($low{$m} == 0 || $v < $low{$m}) { $low{$m}=$v } if ($v > $high{$m}) { $high{$m} = $v } END { for $x(sort keys %close) { print "$x\t$low{$x}\t$close{$x}\t$high{$x}\n" } } ' > monthly-djia.tsv
504
505# Fetch and format the CPI data:
506curl 'http://data.bls.gov/PDQ/servlet/SurveyOutputServlet?series_id=CUUR0000SA0&years_option=all_years&periods_option=all_periods&output_type=column&output_format=text&delimiter=comma' > cpi-u.txt
507sed '1,/Series Id,Year,/d' cpi-u.txt | sed '/^$/,$d' | cut -d, -f2,3,4 | perl -ne 'print if /,M(0[0-9]|1[012]),/' | perl -pe 's/(\d{4}),M(\d{2}),/$1-$2\t/g' > cpi-u.tsv
508
509# Merge:
510join -t' ' cpi-u.tsv monthly-djia.tsv > annotated-djia.tsv
511perl -ne 'BEGIN{print "Month,Nominal,Real\n"} chomp; ($m,$cpi,$low,$close,$high) = split /\t/; $cpi /= 100.0; print "$m-15,$low;$close;$high,",($low/$cpi),";",($close/$cpi),";",($high/$cpi),"\n"' annotated-djia.tsv > dow.txt
512
513-->
514
515<h2>Common Gotchas</h2>
516
517<p>Here are a few problems that I've frequently run into while using the dygraphs library.</p>
518
519<ul>
520 <li>If your chart doesn't display, be sure to check your browser's JavaScript error console. dygraphs makes every attempt to log errors and warnings, and these can often guide you in the right direction.</li>
521 <li>Make sure your CSV files are readable! If your graph isn't showing up, the XMLHttpRequest for the CSV file may be failing. You can determine whether this is the case using tools like <a href="https://getfirebug.com/">Firebug</a>.</li>
522 <li>Make sure your CSV files are in the correct format. They must be of the form <code>YYYY-MM-DD, series1, series2, </code>… — the older YYYYMMDD as first column is <strong>not</strong> recognised as date any more but as number. And if you set the <code>errorBars</code> property, make sure you alternate data series and standard deviations.</li>
523 <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 Dygraph, put it inside a table with <code>align = center</code> set.</li>
524 <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>
525 <li>Make sure you don't have any trailing commas in your call to the Dygraph constructor or in the options parameter. Firefox, Chrome and Safari ignore these but they can cause a graph to not display in Internet Explorer.</li>
526</ul>
527
528<h2>What next?</h2>
529
530<p>If you need to support Internet Explorer, check out our <a href="ie.html">notes on IE</a>.</p>
531
532<p>To get some inspiration, look at how the <a href="gallery/">charts in our gallery</a> are built.</p>
533
534 </div> <!-- .col-lg-12 -->
535 </div> <!-- /div.row -->
536</div> <!-- /div#main.container -->
537
538<!-- TODO(danvk): add a real footer -->
539<!--@@@IFIMPRINT:<div class="container" style="border:1px solid green; margin-bottom:1ex;">@@@PLACE_IMPRINT_LINK_HERE_IF_NECESSARY@@@</div>:FIIMPRINT@@@-->
540
541 </body>
542</html>