Fiddle
I created this fiddle but when try getImageURI()
from chart (orgchart google charts) one error is generated.
ERROR: "Uncaught TypeError: chart.getImageURI is not a function"
I need to generate an image or a PDF from orgchart created. Is it possible?
google.charts.load('current', {packages:["corechart","orgchart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows([
[{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'},
'', 'The President'],
[{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President</div>'},
'Mike', 'VP'],
['Alice', 'Mike', ''],
['Bob', 'Jim', 'Bob Sponge'],
['Carol', 'Bob', '']
]);
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
google.visualization.events.addListener(chart, 'ready', function () {
$( "#chart_div2" ).append( '<img src="' + chart.getImageURI() + '">' );
});
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {allowHtml:true});
}
similar to Table Charts, Org charts produce HTML <table>
elements, rather than SVG
which is why getImageURI
isn't listed in the Methods section for either chart
recommend using library to convert the HTML to Canvas (html2canvas.js
),
which can then be saved as base64 string,
similar to getImageURI
see this answer, for a little more info on the topic...
Rendering HTML elements to canvas
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With