function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ramesh kopparapu 15ramesh kopparapu 15 

create a chart in visualforce page and want to render as pdf

Hi,
I want to create a chart in visualforce page and want to render as pdf.
I used apex:chart and along renderas pdf doesn't work for me.
I tried google charts(By converting the data into image) also, that is also not working both the cases i am getting empty pdf document.
Dushyant SonwarDushyant Sonwar
Hi Ramesh ,

If you want to show chart on PDF ,  then you can use Google charts. As Apex:chart will not render on PDF.

Could you please post your Code here?

It will help us to identify the issue. 
Did you try creating remote site for Google charts API?

Hope this helps. 
Raj VakatiRaj Vakati
You cannt render charts as pdf .. 
The only options i can suggest is create a dashboard and get the chart image from the dashboard  and use in pdf renders 
ramesh kopparapu 15ramesh kopparapu 15
Thanks Sonwar and Raj,
Below is the sample data that i have tried, when i am converting this as a PDF
<html>
<head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

  <script type="text/javascript">
    google.charts.load("current", {packages:['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    function drawChart() {

      var data = google.visualization.arrayToDataTable([
        ['Element', 'Density', { role: 'style' }],
        ['Copper', 8.94, '#b87333', ],
        ['Silver', 10.49, 'silver'],
        ['Gold', 19.30, 'gold'],
        ['Platinum', 21.45, 'color: #e5e4e2' ]
      ]);

      var options = {
        title: "Density of Precious Metals, in g/cm^3",
        bar: {groupWidth: '95%'},
        legend: 'none',
      };

      var chart_div = document.getElementById('chart_div');
      var chart = new google.visualization.ColumnChart(chart_div);

      // Wait for the chart to finish drawing before calling the getImageURI() method.
      google.visualization.events.addListener(chart, 'ready', function () {
        chart_div.innerHTML = '<img src="' + chart.getImageURI() + '">';
        console.log(chart_div.innerHTML);
      });

      chart.draw(data, options);

  }
  </script>

<div id='chart_div'></div>
</head>
</html>
ramesh kopparapu 15ramesh kopparapu 15
Can you please share me if have any sample code for this recuirement?
Raj VakatiRaj Vakati
I dnt think so you can able to do it
csrviswacsrviswa
Google chart API is not working anymore. Look into below solution.
salesforce-lightning-how-to-generate-pdf-with-charts-and-images (https://csrviswa.medium.com/salesforce-lightning-how-to-generate-pdf-with-charts-and-images-f10f5dfef45e)