My.ADVISOR.com Sign-In
ID
Password

Member Center / Sign-Up
Go to Article
Advanced Search 

ADVISOR TIPS

Discover Free Google Charts for FileMaker Pro

Find out what you can do with the free Google Chart API.

By John Mark Osborne, Database Pros president and owner, and FileMaker Advisor technical editor


There are so many third-party options for charting with FileMaker Pro it's hard to determine which approach will work best for your solution. There are several plug-ins, Flash, cascading style sheets (CSS), and even some solutions using just FileMaker Pro features. Each approach has advantages and disadvantages. Some are free, some require an Internet connection, and others require intimate knowledge of a programming language. Well, here's another method using the Google Chart API. It does require an Internet connection but it's completely free, allowing up to 250,000 API calls per day.

I'll start by mentioning the link to the Google Chart API Developer's Guide. There are so many chart types and options that it's impossible for me to cover them all in a single tip. This link introduces you to all the options available in the Google Chart API. It's also a good idea to check back often because new chart types and options are made available on a regular basis.

To give you a flavor for how the Google Chart API works, I'll create a simple pie chart. Let's start with the format of the URL you need to send from FileMaker Pro to a Web Viewer:

http://chart.apis.google.com/chart?<parameter 1>&<parameter 2>&<parameter n>

You have to modify the format URL to send the parameters for your particular chart and options for a chart to display in a Web Viewer. Here's a URL for a basic pie chart with the minimum number of options (you can type this line into a Web browser to generate a pie chart):

http://chart.apis.google.com/chart?cht=p3&chd=t:60,40,25&chs=600x350

After the initial API call, "cht" refers to the chart type and the type specified is "p3" or 3-dimensional pie chart. Each additional parameter requires an ampersand (&), similar to how parameters are separated by semi-colons in a FileMaker Pro calculation function. The reference to "chd" is for chart data and each value must be separated by a comma. The last parameter or "chs" is the chart size in pixels.

To construct this formula in FileMaker Pro, you want to use fields so the chart can change depending on the current found set or related records or whatever you decide to pass to the Google Chart API. In the example I'm about to show you, the chart type is selected from a global pop-up menu and translated to the Google API parameter using a Case statement. The data for the chart is gathered from a related table using the List function and formatted for Google Charts using the Substitute function. Finally, the height and width of the chart are constructed through a simple reference to two global fields.

"http://chart.apis.google.com/chart?cht=" &

Case(MYTABLE::xChartSelector = "Pie 2D"; "p"; MYTABLE::xChartSelector = "Pie 3D"; "p3") & "&chd=t:" &

Substitute(List(CHARTDATA::value); "¶"; ",") &

"&chs=" & MYTABLE::xHeight & "x" & MYTABLE:xWidth

After you have all the tables and fields from this formula in your solution, all you have to do is place the formula in a script using the Set Web Viewer script step. It requires you to have a Web Viewer you've named using the Object Naming feature in the Object Info palette. Just use the Go to URL... option on the Set Web Viewer script step and enter the calculation formula above.

It's also possible to gather the values from a field in the found set using a looping script. The script loops through all the records in the found set and assembles them in a comma-separated list:

Freeze Window
Go to Record/Request/Page [First]
Loop
  Set Variable [$chd; Value: CHARTDATA::value & "," & $chd]
  Go to Record/Request/Page [Next; Exit after last]
End Loop
Set Variable [$chd; Value: Left($chd; Length($chd) - 1) //Remove last comma]
Set Web Viewer [Object Name: "Chart"; URL: "see formula below"]

The formula for the Set Web Viewer script step changes to the following to accommodate the looping script:

"http://chart.apis.google.com/chart?cht=" &

Case(MYTABLE::xChartSelector = "Pie 2D"; "p"; MYTABLE::xChartSelector = "Pie 3D"; "p3") & "&chd=t:" &

$chd & //This references the script variable from the looping script

"&chs=" & MYTABLE::xHeight & "x" & MYTABLE:xWidth

If you're comfortable with recursive Custom Functions, you could use a technique published in the October/November 2005 issue. It lets you gather values from a found set more quickly than a looping script without leaving the currently selected record.

Adding API calls to modify the chart is as easy as concatenating. For instance, you could collect the labels for the chart using the List function by simply concatenating another line of code to the end of the formula I previously discussed:

& "&chl=" & Substitute(List(DATA::label); "¶"; "|"))

You can see how easy it is to build a URL to implement different chart options, because all you have to do is concatenate different Google Chart API calls, in no particular order.

I suggest exploring the Google Chart API and familiarizing yourself with the plethora of options so you can better inform your customers or employer on the best possible charting solution for their needs.

Discover Free Google Charts

No reader comments ... yet.

    What do YOU think about this topic? Share your advice and thoughts using this form.

    Your Name

    REQUIRED : PUBLIC

    Your E-Mail

    REQUIRED : PRIVATE

    Job, Company

    OPTIONAL : PUBLIC

    City, State, Country

    OPTIONAL : PUBLIC

    Your Web Site

    OPTIONAL : PUBLIC

    Your Comment

    Please help everyone by keeping your comments on-topic, using clean language, and not defaming or making personal attacks.


    Your e-mail address is required, but it will not be displayed to the public or given to anyone. See our Privacy Policy. Comments become visible after they pass our spam filter, and spammers and abusers are permanently blocked. Please report spam or abuse.

    John OsborneTechnical editor John Mark Osborne is president and owner of Database Pros, offering FileMaker resources on the Internet. He is author of Scriptology, a speaker at FileMaker Developer Conferences and Macworld conferences, and a trainer for the Professional Training series created by FileMaker, Inc. http://www.databasepros.com jmo@filemakerpros.com

    Printer-friendly
    page layout

    Keyword Tags: FileMaker, FileMaker Development, FileMaker FileMaker Pro

    ADVISORAMA
    Great opportunities to help others seldom come, but small ones surround us every day.

    ARTICLE INFO

    FileMaker Advisor

    Web Edition: 2008 Week 29, Doc #19500

    Print Edition: August/September 2008, Page 44

    FREE ACCESS FREE ACCESS

    SUBSCRIPTION STATUS
    You are not signed-in. If you are a subscriber to this publication, sign-in above to access locked articles. To subscribe or renew go to www.AdvisorStore.com.

    Subscribe to DATABASED.ADVISOR.com

    Get it all -- every current and past ADVISOR tech/business publication, now all-in-one subscription, with new articles and a huge reference library packed with expert advice, how-to and downloads. Subscribe now to get it all.

    DataBased.Advisor.com

    Subscribe to FileMaker Advisor Magazine

    Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.

    FileMaker.Advisor.com

    Subscribe to Advisor Basics of FileMaker Pro

    Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!

    FileMaker.AdvisorBasics.com

    Showcase Your Smarts

    Submit your tips, techniques and advice and let Advisor promote your business and build your career. Show the world what you know!

    AdvisorTips.com

    Use of this or any other site, content, product or service of Advisor Media constitutes acceptance of Terms of Use.
    Portions copyright ©1983-2008 Advisor Media, Inc. All Rights Reserved.
    Reuse or reproduction of any portion or quantity of Advisor Media's copyrighted content, in any form, for any purpose, requires written permission.
    ADVISOR®, the ADVISOR logo, and other names and logos that incorporate ADVISOR are registered trademarks, trademarks or service marks of Advisor Media, Inc. in the United States and/or other countries.
    Other trademarks are used for identification, editorial or descriptive purposes and are the property of their owners.
    Hosted by Prominic.NET Website powered by
    LOTUS SOFTWARE
    osboj040-02 posted 07/14/2008 modified 01/05/2009 03:44:22 AM ztfmfd/ztfmfd
    domino-144.advisor.com my.advisor.com 01/09/2009 03:03:09 PM