Last week we looked at building a FileMaker 11 native chart based on data that has been parsed into a field-based array.
I happen to like field-based arrays, for reasons I’ll get to in a minute, but is a field-based array really necessary to generate the above chart?
Absolutely not, and today we’re going to look at a method to create the same chart as in part 1, but using a variable-based array. Feel free to follow along in today’s demo file, line-chart-from-local-variable-array, if you are so inclined. Also, if you haven’t yet read last week’s article, I strongly recommend you do so before proceeding.
To briefly recap, our data set is a table of web site visits, by week and by state, beginning in March 2006 and running through June 2011. To parse this data into an array, we use the Fast Summary technique, which walks the found set, grabbing one summarized value per week for each year.
Advantages of using a field array
- When you point the List function (or any aggregate function such as Sum or Max) at a repeating field, it sees all repetitions — whereas when you do the same for a repeating variable, you must specify each rep explicitly. Which would you rather type?
- List ( repeatingField ), or
- List ($array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 ; $array_01 )
- You can easily place repeating fields on a layout and view them as per the “array” screen shot above — this can come in very handy when troubleshooting.
- Clearing or zeroing-out the array is quite simple (see Lookups and Repeaters)
- If you need to generate multiple charts concurrently, simply change the storage type of the repeating fields in the array table from global to regular. Then create and populate a new array record for each chart. (I’m not saying you can’t do multiple charts with variable arrays, just that it will be more convoluted.)
Advantages of using a variable array
- No need to tamper with table or field level schema
- You create your array on the fly via script at run time. This is sometimes referred to as “dynamic instantiation”.
- You only define the “cells” (columns and rows) you actually need
- Clearing or zeroing-out the array is pretty easy once you get the hang of dynamic variable instantiation (see below for more on this)
OK, enough theoretical discussion… what’s different about today’s demo?
The big difference is it doesn’t have an Array table. It doesn’t need one since the array is built in memory. There are three main differences in the script that generates the chart:
a) The “zero out the array” segment. See last week’s posting for why the zeroing out is important.
b) The parse segment. Instead of pushing summarized data into a certain row (repetition) of a certain column (field), we push it into variables that we declare on the fly, i.e., “instantiate dynamically” (more on this below).
c) The clear partial year segment. At the risk of becoming repetitive, see last week’s posting for why this is necessary.
Note that all three segments above have a comment re: the lack of a “Set Variable By Name” step. (For more information see Dynamic Variable Instantiation ). And, finally, here’s the Chart Setup.
Note that all 52 variables for each of the 12 data series are individually enumerated. I’m thinking that there is a smarter way to go about this, but that is code for another day.
2 thoughts on “Array Charting, part 2”
Thanks for the example. This method will also work if you define the array variable as a local variable ( $array[n] ). This way you don’t have to worry about persistence of global variables and clearing them from memory after you perform the script.
You are absolutely right, and I appreciate you pointing that out. I have updated the article and demo file accordingly.
Thank you very much.