Skip to content

Instantly share code, notes, and snippets.

@digital-old-school-journey
Created January 6, 2019 14:36
Show Gist options
  • Select an option

  • Save digital-old-school-journey/b2a387275545e7779e0b6bb8d9b47c17 to your computer and use it in GitHub Desktop.

Select an option

Save digital-old-school-journey/b2a387275545e7779e0b6bb8d9b47c17 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.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',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
google.visualization.events.addListener(chart, 'ready', function () {
save_to_the_server(chart.getImageURI());
// console.log(chart.getImageURI());
});
chart.draw(data, options);
}
function save_to_the_server(data){
try{
jQuery.ajax({
type:'POST',
url: "png.php",
data: {
op: 'create',
image_data: data
},
success:function(data) {
console.log(data);
}
});
}catch(ex){
console.log(ex.description);
}
}
jQuery(document).ready(function(){
jQuery('#btn_click').click(function(){
try{
window.location.href = 'png.php?op=download';
}catch(ex){
console.log(ex.description);
}
});
});
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div><hr/>
<button id="btn_click" name="btn_click">Download</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment