我正在使用SVG.toDataURL()将c3js图导出到PNG图像。导出图表到PNG正常工作。导出c3.js折线图到PNG图像不起作用
在折线图的情况下,它们不能正确渲染。例如
- x和y轴宽度增加。
- 线条不正确,而不是线条显示深黑色区域。
下面是导出为png当我使用canvag库
function exportImageAsPNG(){
var svgElements = $("#chart").find('svg');
var svg ;
svgElements.each(function() {
svg = this;
});
var img = document.getElementById("fromcanvas");
svg.toDataURL("image/png", {
callback: function(data) {
img.setAttribute("src", data)
}
})
}
同样的事情发生的代码。
var $container = $('#chart'),
content = $container.html().trim(),
canvas = document.getElementById('svg-canvas');
// Draw svg on canvas
canvg(canvas, content);
// Change img be SVG representation
var theImage = canvas.toDataURL('image/png');
$("#hiddenPng").attr('href', theImage);
$("#hiddenPng span").trigger("click");
见这个家伙的答案在这里 - > http://stackoverflow.com/a/37245183/368214 – mgraham