Created
November 2, 2012 11:52
-
-
Save anonymous/4000635 to your computer and use it in GitHub Desktop.
Open Google Chart V3 in a new window as an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="https://www.google.com/jsapi"></script> | |
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script> | |
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
google.load("visualization", "1", {packages:["corechart"]}); | |
google.setOnLoadCallback(drawChart); | |
function drawChart() { | |
var data = google.visualization.arrayToDataTable([ | |
['Year', 'Sales', 'Expenses'], | |
['2004', 1000, 400], | |
['2005', 1170, 460], | |
['2006', 660, 1120], | |
['2007', 1030, 540] | |
]); | |
var options = { | |
title: 'Company Performance' | |
}; | |
var chart = new google.visualization.LineChart(document.getElementById('chart_div')); | |
chart.draw(data, options); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="chart_div" style="width: 900px; height: 500px;"></div> | |
<canvas id="chart_div_canvas"></canvas> | |
<input type="button" value="Open as image in a new window" id="chart_div_button" /> | |
<script type="text/javascript"> | |
jQuery.noConflict(); | |
jQuery('#chart_div_button').click(function(){ | |
canvg(document.getElementById('chart_div_canvas'), jQuery('#chart_div div div').html()); | |
jQuery('#chart_div').hide(); | |
var canvas = document.getElementById('chart_div_canvas'); | |
var img = canvas.toDataURL("image/png"); | |
window.open(img); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment