Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <script src="http://dygraphs.com/dygraph-dev.js"></script>
</head>
<body>
  <!-- You may set style: "width: ...; height: ..." to size the chart -->
  <div id="graph"></div>
</body>
</html>
 
/*
Relevant CSS classes include:
Labels on the X & Y axes:
.dygraph-axis-label
.dygraph-axis-label-x
.dygraph-axis-label-y
.dygraph-axis-label-y2
Chart labels, see http://dygraphs.com/tests/styled-chart-labels.html
.dygraph-title
.dygraph-xlabel
.dygraph-ylabel
.dygraph-y2label
The legend, see http://dygraphs.com/tests/series-highlight.html
.dygraph-legend
*/
.dygraph-title {
    color: gray;
}
 
// Calculate the min/max y value in the Dygraph's data set.
function calcMinMax(g) {
  var ymin = g.getValue(0, 1), ymax = g.getValue(0, 1), v;
  for (var i = 0; i < g.numRows(); i++) {
    for (var j = 1; j < g.numColumns(); j++) {
      y = g.getValue(i, j);
      if (y < ymin) {
        ymin = y;
      } else if (y > ymax) {
        ymax = y;
      }
    }
  }
  return [ymin, ymax];
}
g = new Dygraph(document.getElementById("graph"),
                 // For possible data formats, see http://dygraphs.com/data.html
                 // The x-values could also be dates, e.g. "2012/03/15"
                 "X,Y,Z\n" +
                 "1,1,3\n" +
                 "2,2,6\n" +
                 "3,4,8\n" +
                 "4,6,9\n" +
                 "5,8,9\n" +
                 "6,10,8\n" +
                 "7,12,6\n" +
                 "8,10,3\n",
                 {
                     // options go here. See http://dygraphs.com/options.html
                     legend: 'always',
                     animatedZooms: true,
                     title: 'dygraphs chart template',
                     underlayCallback: function(ctx, area) {
                       var mm = calcMinMax(this),
                           ymin = mm[0],
                           ymax = mm[1],
                           canvasYmin = this.toDomYCoord(ymin),
                           canvasYmax = this.toDomYCoord(ymax);
                       ctx.strokeStyle= 'red';
                       ctx.beginPath();
                       ctx.moveTo(area.x, canvasYmin);
                       ctx.lineTo(area.x + area.w, canvasYmin);
                       ctx.moveTo(area.x, canvasYmax);
                       ctx.lineTo(area.x + area.w, canvasYmax);
                       ctx.closePath();
                       ctx.stroke();       
                     }
                 });
                 
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers