Xportability / css-to-pdf

Convert any HTML page or region to PDF - supports CSS, SVG, embedded XML objects, and more..
http://www.cloudformatter.com/CSS2Pdf
206 stars 78 forks source link

Add texts to google chart legend breaks pdf conversion #77

Open carduque opened 6 years ago

carduque commented 6 years ago

Hello, On a google chart, if I have a javascript function to add absolute values to legend, PDF conversion returns error. This is my function:

google.visualization.events.addListener(chart, 'ready', function () {
      var rowIndex = 0;
      Array.prototype.forEach.call(document.getElementById('AnswersNPS_div_').getElementsByTagName('text'), function(label) {
        // find legend labels
        if ((label.getAttribute('text-anchor') === 'start') && (label.getAttribute('fill') !== '#ffffff')  && (label.getAttribute('fill') !== '#000000')) {
          label.innerHTML += ' (' + data.getValue(rowIndex++, 1) + ')';
        }
      });
    });

Do you know why?

kbrown01 commented 6 years ago

I would need to see more of the code. Are you adding in the SVG namespace as required in the Google Chart examples? Since the above seems to be your only event for "ready", I would think you are not.

See http://jsfiddle.net/w1rpjxoe/

Specifically the function AddNamespace() that is called in 'ready'.

carduque commented 6 years ago

I added to that example the function I need to modify legend and it works: http://jsfiddle.net/wn2fg04z/2/

It is code javascript in the middle of the div. Is there any way to include it in the middle without breaking pdf generation? Not working version: http://jsfiddle.net/wn2fg04z/9/