简体   繁体   中英

SVG Image not converted properly to Canvas using canvg

Original SVG Chart

原始图表

Rendered Canvas Chart 渲染的画布图

This is the code I am using to convert to canvas

svg = $('svg').parent().html()
canvg('canvas', svg)
canvas = document.getElementById("canvas")
img_PNG = "<img src='#{canvas.toDataURL()}' />"

$('.chart').html(img_PNG)

Kindly help in sorting out this issue.

Pass the canvas element to canvg

svg = $('svg').parent().html()
canvas = document.getElementById("canvas")
canvg(canvas, svg)
img_PNG = "<img src='#{canvas.toDataURL()}' />"

$('.chart').html(img_PNG)

The fact that only the bars are missing..i assume u have applied some animation to the bars..and svg is getting attached to the canvas before the animation..try to apply this code after animation and not before

img_PNG = " < img src='#{canvas.toDataURL()}' />"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM