|
|
ADVISOR TIPS
Discover Free Google Charts for FileMaker Pro
Find out what you can do with the free Google Chart API.
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.
Technical 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
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
Web Edition: 2008 Week 29, Doc #19500Print Edition: August/September 2008, Page 44
FREE ACCESS
|
SUBSCRIPTION STATUSYou 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.
FileMaker Advisor Sponsors
|
 ![]()

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.![]() 
Read the advanced guide to creating custom business database solutions with FileMaker software. Subscribe now to gain access to all the archives and downloads.![]() 
Learn the fundamentals of using FileMaker Pro software. Every issue gives you step-by-step instructions on creating the databases you need. Subscribe now!![]()
![]()
![]()
 ![]()

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