admin管理员组文章数量:1323586
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});
}
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});
}
Share
Improve this question
edited Apr 22, 2017 at 3:04
WhiteHat
61.3k7 gold badges53 silver badges136 bronze badges
asked Jul 28, 2016 at 9:35
MarinMarin
1,0201 gold badge10 silver badges37 bronze badges
2 Answers
Reset to default 3similar 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
remend 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
try this code:
function printImg() {
html2canvas($('#chart_div').get(0)).then( function (canvas) {
var image = convertCanvasToImage(canvas);
var htmlToPrint = image.outerHTML ;
newWin = window.open("");
newWin.document.write(htmlToPrint);
newWin.print();
newWin.close();
});
}
Don't forget to include html2canvas.js
本文标签: javascriptgetImageURI() not work from orgchart by googleStack Overflow
版权声明:本文标题:javascript - getImageURI() not work from orgchart by google - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742108264a2421124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论