1

I have a custom object and in the layout I have a Visualforce Page displayed. The VF utilizes <apex:chart> and JS to create graph based on field in the object. I want to create a report of the object to display a summarized view of the object's fields and to display the chart. From what I've read with the deprecating of Google Charts, it's not possible to render such charts to a PDF. I've been trying to figure if there is some way to create a static version of the image. I've noticed that the standard Printable View action on Salesforce successfully renders the embedded VF chart into a PDF, although its formatting is not great and gives more than I want to show. Is there anyway to utilize this built in action or customize it, etc.?

Here is the page for my chart for reference:

<apex:page standardController="Consumable_Analysis__c" >
<script>
// initialCost, subsqCost, and currentMethod are all taken from the object
//var declarations    
function yearCalc(m1,b1,m2,b2) {//...}
function createLinearData(m1,b1,m2,b2,length){//...} 
data.push({'name':startYear, 'data1':0,'data2':0});
years = yearCalc(subsqCost,initialCost,currentMethod,currentMethod);
createLinearData(subsqCost,initialCost,currentMethod,currentMethod,years);
</script>
<apex:chart height="500" width="750" data="data" >
      <apex:legend position="right" />
      <apex:axis type="Numeric" position="left" fields="data1"
        title="Total Cost of Method" grid="true" />
      <apex:axis type="Category" position="bottom" fields="name"
        title="Years From Purchase"/>
     <apex:lineSeries title="Future Cost Per Year" axis="left" fill="false" 
          xField="name" yField="data1" markerSize="2" smooth="2" />
     <apex:lineSeries title="Current Cost Per Year" axis="left" fill="false" 
          xField="name" yField="data2" markerSize="2"/>
</apex:chart>
</apex:page>
  • 1
    We had to implement a heroku service that used jfree.org/jfreechart to produce our charts as an image and return them to the PDF rendered VF page. Not sure if that is needed for your solution but that is how we ended up doing it a few years ago....There may be a better option now though. – Eric Dec 7 '16 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.