4 name
: 'Independent Series',
5 title
: 'Independent Series',
6 setup
: function(parent
) {
8 "<p>By using the <i>connectSeparated</i> attribute, it's possible to display a chart of several time series with completely independent x-values.</p> ",
10 "<p>The trick is to specify values for the series at the union of the x-values of all series. For one series' x values, specify <code>null</code> for each of the other series.</p> ",
12 "<div id='graph' style='float: right; margin-right: 50px; width: 400px; height: 300px;'></div> ",
13 "<p>For example, say you had two series:</p> ",
17 " <table class='thinborder'> ",
18 " <tr><th>x</th><th>A</th></tr> ",
19 " <tr><td>2</td><td>2</td></tr> ",
20 " <tr><td>4</td><td>6</td></tr> ",
21 " <tr><td>6</td><td>4</td></tr> ",
24 "<td valign=top style='padding-left:25px;'> ",
25 " <table class='thinborder'> ",
26 " <tr><th>x</th><th>B</th></tr> ",
27 " <tr><td>1</td><td>3</td></tr> ",
28 " <tr><td>3</td><td>7</td></tr> ",
29 " <tr><td>5</td><td>5</td></tr> ",
34 "<p>Then you would specify the following CSV or native data:</p> ",
38 "<pre id='csv1'></pre> ",
40 "<td valign=top style='padding-left: 25px;'>",
42 "<pre id='native1'></pre> ",
46 "<h3>Encoding a gap</h3>",
47 "<p>There's one extra wrinkle. What if one of the series has a missing ",
48 "value, i.e. what if your series are something like </p> ",
53 " <table class='thinborder'> ",
54 " <tr><th>x</th><th>A</th></tr> ",
55 " <tr><td>2</td><td>2</td></tr> ",
56 " <tr><td>4</td><td>4</td></tr> ",
57 " <tr><td>6</td><td>(gap)</td></tr> ",
58 " <tr><td>8</td><td>8</td></tr> ",
59 " <tr><td>10</td><td>10</td></tr> ",
62 "<td valign=top style='padding-left:25px;'> ",
63 " <table class='thinborder'> ",
64 " <tr><th>x</th><th>B</th></tr> ",
65 " <tr><td>1</td><td>3</td></tr> ",
66 " <tr><td>3</td><td>5</td></tr> ",
67 " <tr><td>5</td><td>7</td></tr> ",
72 "<div id='graph2' style='float: right; margin-right: 50px; width: 400px; height: 300px;'></div> ",
73 "<p>The gap would normally be encoded as a null, or missing value. But when you use <code>connectSeparatedPoints</code>, that has a special meaning. Instead, you have to use <code>NaN</code>. This is a bit of a hack, but it gets the job done.</p> ",
78 "<pre id='csv2'></pre> ",
80 "<td valign=top style='padding-left: 25px;'> ",
82 "<pre id='native2'></pre> ",
84 "</tr></table>"].join("\n");
87 document
.getElementById("csv1").textContent
=
96 document
.getElementById("native1").textContent
=
106 document
.getElementById("csv2").textContent
=
116 document
.getElementById("native2").textContent
=
123 " [6, NaN, null],\n" +
125 " [10, 10, null]\n" +
128 var g1
= new Dygraph(
129 document
.getElementById('graph'),
139 labels
: ['x', 'A', 'B' ],
140 connectSeparatedPoints
: true,
146 document
.getElementById('graph2'),
157 labels
: ['x', 'A', 'B' ],
158 connectSeparatedPoints
: true,