+ 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.

Thanks.
Siva SakthiSiva Sakthi
Hi Rohit,

Refer these Links: 1.  http://developer.force.com/cookbook/recipe/easy-visualforce-charts-with-javascript-remoting--google-charts-api
2. https://developer.salesforce.com/forums/?id=906F0000000BPXsIAO
3. https://developer.salesforce.com/forums/?id=906F000000098nHIAQ

Thanks
Siva

 
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.

Thanks
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 - 

https://developer.salesforce.com/forums/?id=906F000000099LRIAY


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
www.ajaydubedi.com
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 = 'https://image-charts.com/chart?cht=bvg&chs=580x400&chdl=Offer|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 :

https://documentation.image-charts.com