Using Google Charts in Email Messages Using AMPscript

From $1

    This document contains conceptual and procedural information about including Google Chart information in an email message.

    NOTE: Google Chart API usage may change without notification. Please review the latest Google Chart information at the link above to ensure these instructions will still function.

    What are Google Charts in Email Messages

    The Google Chart API allows you to provide information from a data extension and get a dynamic chart to include in your email message as an image.

    Why Use Google Charts in Email Messages

    Using the Google Chart API, you can include a dynamic chart with up-to-date information (taken at the time of the send) in your email messages. Depending on the data extension you use, you can either send the same chart to all subscribers in the send or use information particular to each subscriber to create the chart.

    How to Use Google Charts in Email Messages

    You must create three elements to include a Google Chart in your email message:

    1. The data extension to hold the chart information
    2. The AMPscript to transfer information from the data extension to the Google Chart API
    3. The email message to send to the subscriber (which includes the AMPscript)

    The Data Extension

    The data extension structure varies depending on your chart needs. In this example, the data extension contains fields for 5 individual cases and 5 individual months.

    The AMPscript

    The AMPscript below takes the information from a data extension and concatenates that information into a URL for use with the Google Chart API.

    %%[
    Var @url, @row
    Set @row = Row(LookupRows("Graph Data",_SubscriberKey),1)
    Set @url = "http://chart.googleapis.com/chart?chs=300x225&chxr=0,0,10&chxt=y&chds=0,10&chd=t:"
    Set @url = Concat(@url,Field(@row,"cases_1"))
    Set @url = Concat(@url,",",Field(@row,"cases_2"))
    Set @url = Concat(@url,",",Field(@row,"cases_3"))
    Set @url = Concat(@url,",",Field(@row,"cases_4"))
    Set @url = Concat(@url,",",Field(@row,"cases_5"))
    Set @url = Concat(@url,"&cht=bvg&chl=")
    Set @url = Concat(@url,Field(@row,"month_1"))
    Set @url = Concat(@url,"%7C",Field(@row,"month_2"))
    Set @url = Concat(@url,"%7C",Field(@row,"month_3"))
    Set @url = Concat(@url,"%7C",Field(@row,"month_4"))
    Set @url = Concat(@url,"%7C",Field(@row,"month_5"))
    ]%%

    The Email Message

    In addition to the AMPscript shown above, the email message includes an HTML div section that takes the Google Chart and places it inside the email message:

    <div style="text-align: center; ">
    <img vspace="0" hspace="0" border="0" src="%%=v(@url)=%%" title="googlechart" alt="CRMpiechart" /><br />
    </div>

    The Final Product

    The sample email below shows the information taken from the data extension and rendered into an image via the Google Chart API:

    Chart.jpg


    This page was last updated by Ryan Williams on Thu, 22 Mar 2012 15:40:32 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 26085 backwards:
       

    Tags: (Edit tags)
    • No tags
    FileSizeDateAttached by 
     Chart.jpg
    No description
    29.41 kB10:06, 7 Feb 2012AdminActions
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin