0

Original SVG Chart

Original Chart

Rendered Canvas 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.

Kiran Kumar
  • 1,610
  • 3
  • 16
  • 22

2 Answers2

1

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)
Mahesh
  • 6,378
  • 2
  • 26
  • 35
0

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()}' />"