X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=gallery%2Findependent-series.js;h=1a1e9020bd31603c2886ed63b9ed615291480822;hb=f808e16e56550f5260f4cf8c335424925e23e6b5;hp=5de2e8b45b422e23ea11728e5393c68c1c528b59;hpb=795b16307db2a673ba7aa3452f6f6b0e93baeb3a;p=dygraphs.git diff --git a/gallery/independent-series.js b/gallery/independent-series.js index 5de2e8b..1a1e902 100644 --- a/gallery/independent-series.js +++ b/gallery/independent-series.js @@ -1,88 +1,88 @@ -// Use this as a template for new Gallery entries. +/*global Gallery,Dygraph,data */ Gallery.register( 'independent-series', { name: 'Independent Series', title: 'Independent Series', setup: function(parent) { - parent.innerHTML = - "

By using the connectSeparated attribute, it's possible to display a chart of several time series with completely independent x-values.

\ -\ -

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 null for each of the other series.

\ -\ -
\ -

For example, say you had two series:

\ - \ - \ - \ -
\ - \ -
\ - \ - \ - \ - \ -
xA
22
46
64
\ -
\ - \ - \ - \ - \ - \ -
xB
13
37
55
\ -
\ -\ -

Then you would specify the following CSV or native data:

\ - \ - \ - \ -
\ - (CSV) \ -
 \
-    
\ - (native) \ -
 \
-    
\ -\ -

Encoding a gap

\ -

There's one extra wrinkle. What if one of the series has a missing \ - value, i.e. what if your series are something like

\ -\ - \ - \ - \ -
\ - \ -
\ - \ - \ - \ - \ - \ - \ -
xA
22
44
6(gap)
88
1010
\ -
\ - \ - \ - \ - \ - \ -
xB
13
35
57
\ -
\ -\ -
\ -

The gap would normally be encoded as a null, or missing value. But when you use connectSeparatedPoints, that has a special meaning. Instead, you have to use NaN. This is a bit of a hack, but it gets the job done.

\ -\ - \ - \ - \ -
\ - (CSV) \ -
 \
-    
\ - (native) \ -
 \
-    
" + parent.innerHTML = [ + "

By using the connectSeparated attribute, it's possible to display a chart of several time series with completely independent x-values.

", + "", + "

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 null for each of the other series.

", + "", + "
", + "

For example, say you had two series:

", + " ", + " ", + " ", + "
", + " ", + "
", + " ", + " ", + " ", + " ", + "
xA
22
46
64
", + "
", + " ", + " ", + " ", + " ", + " ", + "
xB
13
37
55
", + "
", + "", + "

Then you would specify the following CSV or native data:

", + " ", + " ", + " ", + "
", + "(CSV) ", + "
 ",
+    "
", + "(native) ", + "
 ",
+    "
", + "", + "

Encoding a gap

", + "

There's one extra wrinkle. What if one of the series has a missing ", + "value, i.e. what if your series are something like

", + "", + " ", + " ", + " ", + "
", + " ", + "
", + " ", + " ", + " ", + " ", + " ", + " ", + "
xA
22
44
6(gap)
88
1010
", + "
", + " ", + " ", + " ", + " ", + " ", + "
xB
13
35
57
", + "
", + "", + "
", + "

The gap would normally be encoded as a null, or missing value. But when you use connectSeparatedPoints, that has a special meaning. Instead, you have to use NaN. This is a bit of a hack, but it gets the job done.

", + "", + " ", + " ", + " ", + "
", + "(CSV) ", + "
 ",
+    "
", + "(native) ", + "
 ",
+    "
"].join("\n"); }, run: function() { document.getElementById("csv1").textContent = @@ -126,7 +126,7 @@ Gallery.register( " [10, 10, null]\n" + "]"; - var g1 = new Dygraph( + new Dygraph( document.getElementById('graph'), [ [1, null, 3], @@ -143,19 +143,18 @@ Gallery.register( } ); - g2 = new Dygraph( + new Dygraph( document.getElementById('graph2'), -'x,A,B \n' + -'1,,3 \n' + -'2,2, \n' + -'3,,5 \n' + -'4,4, \n' + -'5,,7 \n' + -'6,NaN, \n' + -'8,8, \n' + -'10,10, \n' - , { - labels: ['x', 'A', 'B' ], + 'x,A,B \n' + + '1,,3 \n' + + '2,2, \n' + + '3,,5 \n' + + '4,4, \n' + + '5,,7 \n' + + '6,NaN, \n' + + '8,8, \n' + + '10,10, \n', + { connectSeparatedPoints: true, drawPoints: true }