Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getImageURI() not work from orgchart by google

Tags:

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});
}
like image 242
Marin Avatar asked Jul 28 '16 09:07

Marin


1 Answers

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

like image 114
WhiteHat Avatar answered Sep 28 '22 03:09

WhiteHat