Leveraging Google Charts API provides a great way to include dynamic charts in your S-Docs.
You can find more information on Google charts here: http://code.google.com/apis/chart/
This functionality requires an entry in Salesforce's Remote Site Settings.
- Click Your Name > Setup > Security Controls > Remote Site Settings.
- Click New Remote Site button.
- Set the Remote Site Name field to SDOCS3.
- Set the Remote Site URL field to http://chart.apis.google.com
- Make sure Active is checked and then click the Save button.
Here are a few examples of Google charts:
The charts work by passing the Salesforce data to the Google API, which in turn dynamically builds and returns the chart as a PNG image.
Images are rendered by using one URL request per chart. For example, you can manipulate the values in the following URL to render a different pie chart:
The link above will return the following image:
As you may begin to see, using Google Charts API is all about creating these URLs where you pass in the data points, legends and chart options. Depending on the chart, some of these URLs can be long and a bit complex.
Rather than building complex logic within S-Docs to create these URLs, we again leverage Salesforce formula fields to do the heavy lifting.
Here is a great tutorial from Salesforce on how to create Google Charts using a formula field:
The above tutorial will walk through how to build the following formula field to display a Won/Loss pie chart:
Then, we simply drop this formula field into our S-Doc template (be sure to check Contains Rich Text box).
While more complex, another approach is to build the Google Chart API URL in your S-Doc Template and then mix in field values. This may offer you greater control. Using syntax similar to the following, you could add the image, where ChartLegend__c would just contain the value “Jan|Feb.”
The Google documentation offers a good performance tip if you plan to embed 5 or more charts. By appending a 1-9 before the “chart.apis.google.com,” you can have the browser load the charts simultaneously. For example: