<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |