From: Dan Vanderkam Date: Tue, 8 Dec 2009 06:45:44 +0000 (-0800) Subject: suzuki fraction demo X-Git-Tag: v1.0.0~807 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=a87e8e01396f92f3b488b86d6b0dcab5c93a7790;p=dygraphs.git suzuki fraction demo --- diff --git a/docs/index.html b/docs/index.html index e75c9a4..ea84048 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,6 +56,7 @@ +

Charting Fractions

+

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:

+ +
+ +

Fortunately, dygraphs handles both of these for you! Here's a chart and the command that generated it:

+ +
Batting Average for Ichiro Suzuki vs. Mariners (2004)
+
+ + +

Command:

+
+new Dygraph(
+  document.getElementById("baseballdiv"), "suzuki-mariners.txt",
+  {
+    fractions: true, errorBars: true,
+    showRoller: true, rollPeriod: 15
+  });
+
+ +

The fractions option indicates that the values in each column should be parsed as fractions (e.g. "1/2" instead of "0.5"). The errorBars option indicates that we'd like to see a confidence interval around each data point. By default, when fractions is set, you get a Wilson confidence interval. If you look carefully at the chart, you can see that the error bars are asymmetric.

+ +

A couple things to notice about this chart:

+ +

One last demo

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.

diff --git a/docs/suzuki-mariners.txt b/docs/suzuki-mariners.txt new file mode 100644 index 0000000..0b8dfa4 --- /dev/null +++ b/docs/suzuki-mariners.txt @@ -0,0 +1,163 @@ +Game,Suzuki,Mariners +1,1/4,7/35 +2,1/5,13/39 +3,0/4,7/31 +4,3/5,13/39 +5,2/4,4/30 +6,2/5,14/44 +7,2/5,11/36 +8,2/5,12/36 +9,0/5,8/36 +10,0/5,8/32 +11,1/4,5/29 +12,3/4,10/33 +13,2/6,10/47 +14,0/3,4/28 +15,1/3,9/31 +16,0/4,7/31 +17,2/4,12/37 +18,1/4,7/32 +19,1/5,15/40 +20,1/4,13/40 +21,0/5,4/31 +22,0/4,5/32 +23,1/5,9/39 +24,2/4,6/31 +25,2/5,14/39 +26,3/8,13/55 +27,2/4,5/32 +28,1/4,5/28 +29,2/4,12/36 +30,2/4,4/31 +31,1/4,8/34 +32,1/6,18/50 +33,2/4,10/34 +34,2/4,8/31 +35,2/5,12/34 +36,3/5,15/49 +37,2/4,9/34 +38,2/4,6/33 +39,0/3,7/34 +40,3/5,13/36 +41,3/5,8/35 +42,0/3,7/34 +43,1/4,9/29 +44,1/6,12/48 +45,4/5,13/40 +46,1/5,8/35 +47,2/5,11/36 +48,2/5,11/37 +49,1/6,8/40 +50,3/4,10/31 +51,2/4,9/37 +52,2/5,10/38 +53,1/4,5/31 +54,1/2,7/28 +55,2/5,11/36 +56,2/5,11/33 +57,0/4,6/33 +58,1/4,7/32 +59,1/3,10/30 +60,1/3,5/26 +61,1/4,14/36 +62,0/3,2/27 +63,1/3,6/32 +64,3/5,11/35 +65,0/4,9/32 +66,2/4,8/35 +67,1/4,6/30 +68,1/4,5/32 +69,0/3,8/34 +70,1/7,12/61 +71,0/4,8/33 +72,3/5,13/35 +73,0/4,3/30 +74,1/4,9/32 +75,0/4,8/30 +76,2/5,9/35 +77,3/5,12/36 +78,2/4,6/32 +79,0/3,6/33 +80,1/4,6/32 +81,2/5,10/35 +82,1/5,13/38 +83,2/4,14/36 +84,1/4,7/33 +85,0/0,9/32 +86,2/4,7/32 +87,1/4,4/28 +88,1/3,7/33 +89,1/5,13/38 +90,2/4,10/36 +91,2/5,10/42 +92,4/5,18/43 +93,4/5,12/36 +94,1/4,7/29 +95,1/5,9/32 +96,3/5,9/35 +97,1/4,8/30 +98,3/5,12/35 +99,2/5,9/32 +100,3/4,8/35 +101,5/7,18/56 +102,0/4,7/33 +103,3/6,14/46 +104,2/5,10/34 +105,5/5,16/41 +106,1/1,15/42 +107,3/5,9/35 +108,3/6,10/41 +109,0/4,2/34 +110,2/5,12/36 +111,2/5,9/36 +112,3/4,10/32 +113,2/4,7/32 +114,2/5,9/35 +115,0/3,7/32 +116,1/4,11/36 +117,3/4,12/34 +118,4/4,20/47 +119,0/1,5/29 +120,3/4,9/34 +121,4/7,21/52 +122,1/5,11/35 +123,1/4,5/32 +124,1/4,7/35 +125,0/4,7/33 +126,1/5,8/33 +127,2/4,14/35 +128,1/4,12/33 +129,3/6,12/44 +130,3/4,8/33 +131,3/5,16/39 +132,2/3,6/33 +133,3/5,11/37 +134,1/4,11/37 +135,5/5,15/37 +136,1/4,9/35 +137,2/4,5/30 +138,1/5,7/34 +139,2/4,9/34 +140,0/4,6/33 +141,0/4,5/33 +142,2/4,6/28 +143,0/4,7/34 +144,1/4,7/27 +145,1/4,6/30 +146,0/2,6/33 +147,2/4,10/32 +148,1/5,9/36 +149,0/4,8/33 +150,2/4,12/39 +151,5/5,18/41 +152,4/6,24/47 +153,2/4,14/39 +154,1/5,8/36 +155,1/4,13/37 +156,1/4,8/33 +157,2/5,13/37 +158,1/3,10/35 +159,1/5,9/35 +160,3/5,18/41 +161,1/5,10/37 +162,2/4,4/30