gc_out_test.html 1.71 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1 2 3
<html>
  <head>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
incardon's avatar
incardon committed
4
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
Pietro Incardona's avatar
Pietro Incardona committed
5 6 7 8
    <script type="text/javascript">
      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawVisualization);

incardon's avatar
incardon committed
9 10 11 12 13 14 15 16 17 18
function exportToSVG(i)
{
var e = document.getElementById('chart_div'+i);
var svg = e.getElementsByTagName('svg')[0].parentNode.innerHTML;
var pos = svg.lastIndexOf("</svg>");
pos += 6;
svg = svg.substring(0,4)  + " xmlns='http://www.w3.org/2000/svg' xmlns:xlink= 'http://www.w3.org/1999/xlink' " + svg.substring(4,pos);
svgData = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
$(this).attr({'href': svgData,'target': '_blank'});
}
Pietro Incardona's avatar
Pietro Incardona committed
19 20

      function drawVisualization() {
Pietro Incardona's avatar
Pietro Incardona committed
21 22 23 24 25 26 27
var data0 = new google.visualization.DataTable();
data0.addColumn('string','X Axis');
data0.addColumn('number','dataset1');
data0.addColumn('number','dataset2');
data0.addColumn('number','dataset3');
data0.addColumn('number','dataset4');
data0.addRows([
Pietro Incardona's avatar
Pietro Incardona committed
28 29 30 31 32 33 34 35 36 37 38 39
['colum1',2,3,5,6],
['colum2',5,6,1,6],
['colum3',2,1,6,9],
['colum4',1,6,3,2],
['colum5',3,3,0,6],
['colum6',2,1,4,6],
]);
var options0= {
title : 'Example',
vAxis: {title: 'Y Axis'},
hAxis: {title: 'X Axis'},
seriesType: 'bars',
Pietro Incardona's avatar
Pietro Incardona committed
40
series: {3: {type: 'line'}}};
incardon's avatar
incardon committed
41
$("#export_svg0").on("click", function (event) {exportToSVG.apply(this,[0]);});
incardon's avatar
incardon committed
42 43
var chart = new google.visualization.ComboChart(document.getElementById('chart_div0'));
chart.draw(data0, options0);
Pietro Incardona's avatar
Pietro Incardona committed
44 45 46
}</script>
</head>
<body>
incardon's avatar
incardon committed
47
<a href="#" download="graph1.svg" id="export_svg0"><button>Export data into svg</button></a><div id="chart_div0" style="width: 900px; height: 500px;"></div>
Pietro Incardona's avatar
Pietro Incardona committed
48 49
</body>
</html>