Merge pull request #746 from mrcslws/wrong-gap-edge-point
[dygraphs.git] / tests / independent-series.html
CommitLineData
54425b14 1<!DOCTYPE html>
75c589da
DV
2<html>
3 <head>
4 <title>Independent Series</title>
7e5ddc94
DV
5 <!--
6 For production (minified) code, use:
7 <script type="text/javascript" src="dygraph-combined.js"></script>
8 -->
fbd6834a 9 <script type="text/javascript" src="../dist/dygraph.js"></script>
7e5ddc94 10
75c589da
DV
11 <style type="text/css">
12 .thinborder {
13 border-width: 1px;
14 border-spacing: 0px;
15 border-style: solid;
16 border-color: black;
17 border-collapse: collapse;
18 }
19
20 .thinborder td,
21 .thinborder th {
22 border-width: 1px;
23 padding: 5px;
24 border-style: solid;
25 border-color: black;
26 }
27 </style>
28 </head>
29 <body>
7219edb3 30 <h3>Independent Series</h3>
75c589da
DV
31 <p>By using the connectSeparated attribute, it's possible to display a chart of several time series with completely independent x-values.</p>
32
33 <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>
34
c6a0ebba 35 <div id="graph" style="float: right; margin-right: 50px; width: 400px; height: 300px;"></div>
75c589da
DV
36 <p>For example, say you had two series:</p>
37 <table><tr>
38 <td valign=top>
39 <table>
40 <table class=thinborder>
41 <tr><th>x</th><th>A</th></tr>
42 <tr><td>2</td><td>2</td></tr>
c6a0ebba
DV
43 <tr><td>4</td><td>6</td></tr>
44 <tr><td>6</td><td>4</td></tr>
75c589da
DV
45 </table>
46 </td>
47 <td valign=top style="padding-left:25px;">
48 <table class=thinborder>
49 <tr><th>x</th><th>B</th></tr>
50 <tr><td>1</td><td>3</td></tr>
c6a0ebba
DV
51 <tr><td>3</td><td>7</td></tr>
52 <tr><td>5</td><td>5</td></tr>
75c589da
DV
53 </table>
54 </td>
55 </tr></table>
56
57 <p>Then you would specify the following CSV or native data:</p>
58 <table><tr>
59 <td valign=top>
60 (CSV)
61 <pre>X,A,B
621,,3
632,2,
c6a0ebba
DV
643,,7
654,6,
665,,5
676,4,</pre>
75c589da
DV
68 </td>
69 <td valign=top style="padding-left: 25px;">
70 (native)
71 <pre>[
72[1, null, 3],
73[2, 2, null],
c6a0ebba
DV
74[3, null, 7],
75[4, 6, null],
76[5, null, 5],
77[6, 4, null] ]</pre>
75c589da
DV
78 </td>
79 </tr></table>
80
81 <script type="text/javascript">
f6fbf9e0 82 var g1 = new Dygraph(
75c589da
DV
83 document.getElementById("graph"),
84 [
85 [1, null, 3],
86 [2, 2, null],
c6a0ebba
DV
87 [3, null, 7],
88 [4, 5, null],
89 [5, null, 5],
90 [6, 3, null]
75c589da
DV
91 ],
92 {
93 labels: ["x", "A", "B" ],
c6a0ebba
DV
94 connectSeparatedPoints: true,
95 drawPoints: true
75c589da
DV
96 }
97 );
98 </script>
99
141064ff
DE
100 <h3>Encoding a gap</h3>
101 <p>There's one extra wrinkle. What if one of the series has a missing
102 value, i.e. what if your series are something like </p>
103
104 <table><tr>
105 <td valign=top>
106 <table>
107 <table class=thinborder>
108 <tr><th>x</th><th>A</th></tr>
109 <tr><td>2</td><td>2</td></tr>
110 <tr><td>4</td><td>4</td></tr>
111 <tr><td>6</td><td>(gap)</td></tr>
112 <tr><td>8</td><td>8</td></tr>
113 <tr><td>10</td><td>10</td></tr>
114 </table>
115 </td>
116 <td valign=top style="padding-left:25px;">
117 <table class=thinborder>
118 <tr><th>x</th><th>B</th></tr>
119 <tr><td>1</td><td>3</td></tr>
120 <tr><td>3</td><td>5</td></tr>
121 <tr><td>5</td><td>7</td></tr>
122 </table>
123 </td>
124 </tr></table>
125
126 <div id="graph3" style="float: right; margin-right: 50px; width: 400px; height: 300px;"></div>
127 <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>
128
129 <script type="text/javascript">
130 g2 = new Dygraph(
131 document.getElementById("graph3"),
132"x,A,B \n" +
133"1,,3 \n" +
134"2,2, \n" +
135"3,,5 \n" +
136"4,4, \n" +
137"5,,7 \n" +
138"6,NaN, \n" +
139"8,8, \n" +
140"10,10, \n"
141 , {
142 connectSeparatedPoints: true,
143 drawPoints: true
144 }
145 );
146 </script>
147
148 <table><tr>
149 <td valign=top>
150 (CSV)
151 <pre>x,A,B
1521,,3
1532,2,
1543,,5
1554,4,
1565,,7
1576,NaN,
1588,8,
15910,10,</pre>
160 </td>
161 <td valign=top style="padding-left: 25px;">
162 (native)
163 <pre>[ [1, null, 3],
164 [2, 2, null],
165 [3, null, 5],
166 [4, 4, null],
167 [5, null, 7],
168 [6, NaN, null],
169 [8, 8, null],
170 [10, 10, null] ]</pre>
171 </td>
172 </tr></table>
173
1ef9d2f7 174 <h3>Behavior at the edges of the panel for independent series</h3>
175 <p> In case only a part of the whole data is visible (e.g. after zooming in) the lines are
176 drawn to the respective next valid point outside the visible area. </p>
177
178 <table><tr>
179 <td valign=top>
180 <table>
181 <table class=thinborder>
182 <tr><th>x</th><th>A</th></tr>
183 <tr><td>0</td><td>2</td></tr>
184 <tr><td>1</td><td>3</td></tr>
185 <tr><td>2</td><td>3</td></tr>
186 <tr><td>4</td><td>4</td></tr>
187 <tr><td>5</td><td>3</td></tr>
188 <tr><td>6</td><td>3</td></tr>
189 <tr><td>7</td><td>3</td></tr>
190 <tr><td>8</td><td>4</td></tr>
191 </table>
192 </td>
193 <td valign=top style="padding-left:25px;">
194 <table class=thinborder>
195 <tr><th>x</th><th>B</th></tr>
196 <tr><td>0</td><td>1</td></tr>
197 <tr><td>1</td><td>2</td></tr>
198 <tr><td>2</td><td>1</td></tr>
199 <tr><td>8</td><td>2</td></tr>
200 </table>
201 </td>
202 </tr></table>
203
204 <div id="graph2" style="float: right; margin-right: 50px; width: 400px; height: 300px;"></div>
205 <p>Both graphs have no value at the right edge of the panel (x=3). The lines that are drawn to the right edge are determined by their respective next valid value outside the visible area.
206 Therefore it is neither necessary that the next valid values are on the same point nor that they have the same index (index 4 for the green line and index 8 for the blue line).</p>
207 <p>Use double click to unzoom and see the currently invisible points</p>
208
209 <script type="text/javascript">
210 g2 = new Dygraph(
211 document.getElementById("graph2"),
212"x,A,B \n" +
213"0,2,1 \n" +
214"1,3,2 \n" +
215"2,3,1 \n" +
216"3,, \n" +
217"4,4, \n" +
218"5,3, \n" +
219"6,3, \n" +
220"7,3, \n" +
221"8,4,2 \n"
222
223 , {
224 connectSeparatedPoints: true,
225 drawPoints: true,
226 pointSize: 3,
227 highlightCircleSize: 5,
228 dateWindow: [0,3]
229 }
230 );
231 </script>
232
233 <table><tr>
234 <td valign=top>
235 Index
236 <pre>&nbsp;
2370
2381
2392
2403
2414
2425
2436
2447
2458</pre>
246 </td>
247 <td valign=top>
248 (CSV)
249 <pre>x,A,B
2500,2,1
2511,3,2
2522,3,1
2533,,
2544,4,
2555,3,
2566,3,
2577,3,
2588,4,2</pre>
259 </td>
260 <td valign=top style="padding-left: 25px;">
261 (native)
262 <pre>[
263 [0, 2, 1],
264 [1, 3, 2],
265 [2, 3, 1],
266 [3, null, null],
267 [4, 4, null],
268 [5, 3, null],
269 [6, 3, null],
270 [7, 3, null],
271 [8, 4, 2] ]</pre>
272 </td>
273 </tr></table>
c6a0ebba 274
75c589da
DV
275 </body>
276</html>