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
Rohit K SethiRohit K Sethi 

How to create google chart from apex class ?

hi ,

I have to create google chart from apex class and insert the chart into attachement.

Siva SakthiSiva Sakthi
Hi Rohit,

Refer these Links: 1.


Rohit K SethiRohit K Sethi
Hi Siva,

Thanks for reply , Here my requirement is that I want to genrate Pdf for google chart. And when we set the randerAs="Pdf" then no script can be executed. As i find that google chart can be only created thorugh Javascript and Apex:page not support js when it sets as pdf.

Is there any way that I can genrate Chart from Apex class. So that after http callout i can insert the chart in attachement and then it can be easily shown in pdf.

If you have any solution/Idea plz reply.

Ajay K DubediAjay K Dubedi
Hi Rohit,

I have gone through your question. You can use <c:PDFHTML> default lightning component to achieve this.
Please check the link below to get more details -

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
Annu ChoudharyAnnu Choudhary
Hi Rohit,
Google chart is run by javascript but in render as pdf in visualforce page, javascript is not working.
you can use 'ImageChart' API for this. Create an image URL from the apex and then bind it in <img> tag in the VF page. Like This:
In Apex Class : 

String imageUrl = '|Demand&chdlp=b&chd=t:23|0&chco=16BFE7,ff8533&chxt=x,y&chxs=1N*cUSD0sz*&chxl=0:|12-Nov-2019'

In visualforce page : 

<img src="{!imageUrl }"/>

Annu ChoudharyAnnu Choudhary
Here is the reference or image-chart API :