DYGRAPHS hide y2 labels

desc tbd

by Dipak1991

HTML

<script src="http://dygraphs.com/dygraph-combined.js"></script>
<p>The lines should maintain their colors as their visibility is toggled.</p>
<div id="blah"></div>
<p><b>Display: </b>
    <input type="checkbox" id="0" onClick="change(this)" checked />
<label for="0"> UX</label>
    <input type="checkbox" id="1" onClick="change(this)" /><!-- got rid of checked -->
<label for="1"> EX</label>
    <input type="checkbox" id="2" onClick="change(this)" checked />
<label for="2"> JX</label>
    <input type="checkbox" id="3" onClick="change(this)" checked />
<label for="2"> EJ</label>
</p>

JavaScript

chart = new Dygraph(document.getElementById("blah"),
                    "date,UX,EX,JX,EJ\n" +
                    "10,3.0,4.15,133.1,140.1\n" +
        "11,3.3,4.18,100.9,135.3\n" +
                    "12,3.25,4.20,115.9,145.5\n" + 
        "13,3.35,4.16,98.9,106.8\n", 
                      {
        width: 640,
        height: 480,
        labelsSeparateLines: false,
        hideOverlayOnMouseOut: true,
        axisLabelFontSize: 9,
        colors: ['#284785', '#EE1111', '#8AE234', '#00ffff'],   
  series : {
 'UX' : {
  axis : 'y1',
  },
'EX' : {
  axis : 'y1',
  },
  'EJ' : {
  axis : 'y2',
  },
  'JX' : {
  axis : 'y2',
  }
  },
  visibility: [true, false, true, true],
showRangeSelector: true,
rangeSelectorHeight: 30,
labelsDivStyles: { 'textAlign': 'right' },
    title: 'Currency Pair Correlation',
    ylabel: 'Price',
connectSeparatedPoints: true,
strokeWidth: 3,
strokeBorderWidth: 1,
strokeBorderColor: '#000',
drawPoints : true,
    pointSize : 3,
    highlightCircleSize: 10,
drawPointCallback : Dygraph.Circles.HEXAGON,
    drawHighlightPointCallback : Dygraph.Circles.HEXAGON,
   });
  function change(el) {
    chart.setVisibility(el.id, el.checked);
      var y1vis = ($("#0:checked").length + $("#1:checked").length) > 0;
      var y2vis = ($("#2:checked").length + $("#3:checked").length) > 0;      
      if (y1vis){
          $(".dygraph-axis-label-y:not(.dygraph-axis-label-y2)").show();
      } else {
          $(".dygraph-axis-label-y:not(.dygraph-axis-label-y2)").hide();
      }
      if (y2vis){
          $(".dygraph-axis-label-y2").show();
      } else {
          $(".dygraph-axis-label-y2").hide();
      }          
  }