Skip to content

Instantly share code, notes, and snippets.

@christophervigliotti
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophervigliotti/90a9deb279f04b3fef0a to your computer and use it in GitHub Desktop.
Save christophervigliotti/90a9deb279f04b3fef0a to your computer and use it in GitHub Desktop.
Export Dygraph As PNG
<!-- you too can export dygraphs http://dygraphs.com/
as pngs by using this awesome library http://cavorite.com/labs/js/dygraphs-export/ -->
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="//dygraphs.com/dygraph-combined.js"></script>
<script type="text/javascript" src="dygraph-extra.js"></script>
</head>
<body>
<div id="graphdiv" style="width:500px; height:300px;"></div>
<br />
<span id="merge">click here to zoom out and merge canvases into a single image</span>
<br />
<image id="imgExport" style="width:500px; height:300px;" />
<script>
var g = null;
$( document ).ready(function() {
// $('#imgExport').hide();
var data = [[0.0000051, 0.0438], [0.0000102, 0.0459], [0.0000153, 0.048], [0.0000204, 0.0502], [0.0000255, 0.0524], [0.0000306, 0.0548], [0.0000357, 0.0572], [0.0000408, 0.0597], [0.0000459, 0.0623], [0.000051, 0.065], [0.0000561, 0.0678], [0.0000612, 0.0707], [0.0000663, 0.0736], [0.0000715, 0.0767], [0.0000766, 0.0798], [0.0000817, 0.0831], [0.0000868, 0.0864], [0.0000919, 0.0898], [0.000097, 0.0934], [0.000102, 0.097], [0.000107, 0.101], [0.000112, 0.105], [0.000117, 0.109], [0.000122, 0.113], [0.000128, 0.117], [0.000133, 0.121], [0.000138, 0.125], [0.000143, 0.13], [0.000148, 0.135], [0.000153, 0.139], [0.000158, 0.144], [0.000163, 0.149], [0.000168, 0.154], [0.000174, 0.159], [0.000179, 0.165], [0.000184, 0.17], [0.000189, 0.175], [0.000194, 0.181], [0.000199, 0.187], [0.000204, 0.193], [0.000209, 0.199], [0.000214, 0.205], [0.000219, 0.211], [0.000225, 0.217], [0.00023, 0.223], [0.000235, 0.23], [0.00024, 0.237], [0.000245, 0.243], [0.00025, 0.25], [0.000255, 0.257], [0.00026, 0.264], [0.000265, 0.271], [0.00027, 0.278], [0.000276, 0.285], [0.000281, 0.293], [0.000286, 0.3], [0.000291, 0.308], [0.000296, 0.315], [0.000301, 0.323], [0.000306, 0.331], [0.000311, 0.339], [0.000316, 0.347], [0.000322, 0.355], [0.000327, 0.363], [0.000332, 0.371], [0.000337, 0.379], [0.000342, 0.387], [0.000347, 0.395], [0.000352, 0.404], [0.000357, 0.412], [0.000362, 0.42], [0.000367, 0.429], [0.000373, 0.437], [0.000378, 0.446], [0.000383, 0.454], [0.000388, 0.463], [0.000393, 0.471], [0.000398, 0.48], [0.000403, 0.489], [0.000408, 0.497], [0.000413, 0.506], [0.000419, 0.514], [0.000424, 0.523], [0.000429, 0.531], [0.000434, 0.54], [0.000439, 0.549], [0.000444, 0.557], [0.000449, 0.566], [0.000454, 0.574], [0.000459, 0.582], [0.000464, 0.591], [0.00047, 0.599], [0.000475, 0.607], [0.00048, 0.616], [0.000485, 0.624], [0.00049, 0.632], [0.000495, 0.64], [0.0005, 0.648], [0.000505, 0.656], [0.00051, 0.664], [0.000515, 0.672], [0.000521, 0.68], [0.000526, 0.687], [0.000531, 0.695], [0.000536, 0.702], [0.000541, 0.71], [0.000546, 0.717], [0.000551, 0.724], [0.000556, 0.731], [0.000561, 0.738], [0.000567, 0.745], [0.000572, 0.752], [0.000577, 0.759], [0.000582, 0.766], [0.000587, 0.772], [0.000592, 0.779], [0.000597, 0.785], [0.000602, 0.791], [0.000607, 0.797], [0.000612, 0.803], [0.000618, 0.809], [0.000623, 0.815], [0.000628, 0.821], [0.000633, 0.826], [0.000638, 0.832], [0.000643, 0.837], [0.000648, 0.842], [0.000653, 0.848], [0.000658, 0.853], [0.000663, 0.857], [0.000669, 0.862], [0.000674, 0.867], [0.000679, 0.872], [0.000684, 0.876], [0.000689, 0.88], [0.000694, 0.885], [0.000699, 0.889], [0.000704, 0.893], [0.000709, 0.897], [0.000715, 0.9], [0.00072, 0.904], [0.000725, 0.908], [0.00073, 0.911], [0.000735, 0.915], [0.00074, 0.918], [0.000745, 0.921], [0.00075, 0.924], [0.000755, 0.927], [0.00076, 0.93], [0.000766, 0.933], [0.000771, 0.936], [0.000776, 0.939], [0.000781, 0.941], [0.000786, 0.944], [0.000791, 0.946], [0.000796, 0.948], [0.000801, 0.951], [0.000806, 0.953], [0.000811, 0.955], [0.000817, 0.957], [0.000822, 0.959], [0.000827, 0.961], [0.000832, 0.962], [0.000837, 0.964], [0.000842, 0.966], [0.000847, 0.967], [0.000852, 0.969], [0.000857, 0.97], [0.000863, 0.972], [0.000868, 0.973], [0.000873, 0.975], [0.000878, 0.976], [0.000883, 0.977], [0.000888, 0.978], [0.000893, 0.979], [0.000898, 0.98], [0.000903, 0.981], [0.000908, 0.982], [0.000914, 0.983], [0.000919, 0.984], [0.000924, 0.985], [0.000929, 0.986], [0.000934, 0.986], [0.000939, 0.987], [0.000944, 0.988], [0.000949, 0.989], [0.000954, 0.989], [0.000959, 0.99], [0.000965, 0.99], [0.00097, 0.991], [0.000975, 0.991], [0.00098, 0.992], [0.000985, 0.992], [0.00099, 0.993], [0.000995, 0.993], [0.001, 0.994], [0.00101, 0.994], [0.00101, 0.994], [0.00102, 0.995], [0.00102, 0.995]];
g = new Dygraph(
document.getElementById("graphdiv"),
data,
{
strokeWidth: 2,
drawPoints: true,
fillGraph: true,
colors: ["rgb(51,204,204)",
"rgb(255,100,100)"],
labels: ['a label','another label'],
legend: 'always'
}
);
console.log(Dygraph);
});
$("#merge").click(function() {
g.resetZoom();
Dygraph.Export.asPNG(g,imgExport);
// $('#imgExport').show();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment